package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.util.UUIDUtils;
import cn.stylefeng.guns.sys.modular.system.entity.*;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.EmployeePositionEnum;
import cn.stylefeng.guns.sys.modular.system.mapper.AttendEmployeeMonthMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.AttendAuditDdSupervisorParam;
import cn.stylefeng.guns.sys.modular.system.model.params.AttendAuditManagerSetParam;
import cn.stylefeng.guns.sys.modular.system.model.params.AttendEmployeeMonthParam;
import cn.stylefeng.guns.sys.modular.system.model.result.AttendAuditManagerSetResult;
import cn.stylefeng.guns.sys.modular.system.model.result.AttendEmployeeMonthAddValidationResult;
import cn.stylefeng.guns.sys.modular.system.model.result.AttendEmployeeMonthResult;
import cn.stylefeng.guns.sys.modular.system.service.*;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.AttendAuditStatusEnum;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.AttendEmployeeSynchronousStatusEnum;
import cn.stylefeng.guns.sys.modular.system.model.params.AttendAuditBtyArchivesParam;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.cxf.common.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 出勤_月度员工档案信息表 服务实现类
 * </p>
 *
 * @author wjk
 * @since 2021-09-14
 */
@Service
public class AttendEmployeeMonthServiceImpl extends ServiceImpl<AttendEmployeeMonthMapper, AttendEmployeeMonth> implements AttendEmployeeMonthService {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    private AttendAuditBtyAreaService attendAuditBtyAreaService;

    @Resource
    private AttendAuditBtyArchivesService attendAuditBtyArchivesService;

    @Resource
    private BtyBxdaService btyBxdaService;

    @Resource
    private AttendAuditService attendAuditService;

    @Resource
    private AttendDismissedService attendDismissedService;


    @Resource
    private BtyArchivesService btyArchivesService;


    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
    SimpleDateFormat sdfh = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
    SimpleDateFormat sdfs = new SimpleDateFormat("yyyyMMddHHmmss");
     @Override
    public void add(AttendEmployeeMonthParam param){
        AttendEmployeeMonth entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(AttendEmployeeMonthParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(AttendEmployeeMonthParam param){
        AttendEmployeeMonth oldEntity = getOldEntity(param);
        AttendEmployeeMonth newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }
    @Override
    public AttendEmployeeMonthResult findBySpec(AttendEmployeeMonthParam param){
        return null;
    }

    @Override
    public List<AttendEmployeeMonthResult> findListBySpec(AttendEmployeeMonthParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(AttendEmployeeMonthParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(AttendEmployeeMonthParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private AttendEmployeeMonth getOldEntity(AttendEmployeeMonthParam param) {
        return this.getById(getKey(param));
    }

    private AttendEmployeeMonth getEntity(AttendEmployeeMonthParam param) {
        AttendEmployeeMonth entity = new AttendEmployeeMonth();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
    /**
     * mysql的批量插入方式，oracle不支持。
     * AttendEmployeeMonth批量增加月度员工考勤表
     * @param list
     */
    @Override
    public int simpleSqlInsertBatch(List<AttendEmployeeMonth> list) {
        if (list == null || list.size() < 1) {
            return 0;
        }
        // 如果提交的列表条数小于提交阀值
        List<AttendEmployeeMonth>[] splitLists = splitLists(list, 50);
        for (List<AttendEmployeeMonth> tempList : splitLists) {
            this.baseMapper.addList(tempList);
        }
        return list.size();
    }
    /**
     * 删除当月考勤数据；
     * @author wjk
     * @Date 2021-09-16
     */
    @Override
    public boolean deleteList(String synchronousMonth) {
        //构造条件
        LambdaQueryWrapper<AttendEmployeeMonth> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AttendEmployeeMonth::getSynchronousMonth, synchronousMonth);

        return this.remove(queryWrapper);
    }

    /**
     * 根据店长的手机号码，返回店长下的所有的人员（当月）档案的列表；
     * @author wjk
     * @Date 2021-09-15
     */

    public List<AttendEmployeeMonth> getEmployeeListMonthByDzPhone(String account,String attendMonth) {

        if (ToolUtil.isNotEmpty(account)) {
            String synchronousMonth = sdf.format(new Date());
            //根据店长的电话获取店长的店的信息
            AttendAuditBtyArea attendAuditBtyArea = attendAuditBtyAreaService.getShopInfoByDzPhone(account);
            String shopName = attendAuditBtyArea.getDm();

            if(ToolUtil.isEmpty(shopName)){
                return new ArrayList<AttendEmployeeMonth>();
            }
            //根据店名获取，该店下的员工档案信息(当月);
            LambdaQueryWrapper<AttendEmployeeMonth> queryWrapper = new LambdaQueryWrapper<AttendEmployeeMonth>();
            queryWrapper.eq(AttendEmployeeMonth::getAttendMonth,attendMonth);
            queryWrapper.eq(AttendEmployeeMonth::getDm,shopName);

            List<AttendEmployeeMonth> list = this.list(queryWrapper);
            return list;
        }
        return new ArrayList<AttendEmployeeMonth>();
    }

    /**
     * 删除当月，当店的月度考勤数据；
     * @author wjk
     * @Date 2021-09-16
     */
    @Override
    public boolean deleteList(String synchronousMonth, String dm) {
        //构造条件
        LambdaQueryWrapper<AttendEmployeeMonth> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AttendEmployeeMonth::getSynchronousMonth, synchronousMonth);
        queryWrapper.eq(AttendEmployeeMonth::getDm,dm);
        return this.remove(queryWrapper);
    }
    /**
     * （店长考勤修改页面）根据店长的手机号码，返回该店的店长，所有的审核信息；
     * @author wjk
     * @Date 2021-09-17
     */
    @Override
    public List<AttendAuditManagerSetResult> getEmployeeListMonthByManagerSetParam(AttendAuditManagerSetParam param) {
        //参数中attendMonth 不能为空！！
        param = attendMonthIsNotNullForDz(param);
        List<AttendAuditManagerSetResult> list = this.baseMapper.getEmployeeListMonthByManagerSetParam(param);
        List<AttendAuditManagerSetResult> listNew = setDismissedNote(list);
        return listNew;
    }

    /**
     * 将除去第一条驳回的数据制空
     * @param list
     * @return
     */
    List<AttendAuditManagerSetResult> setDismissedNote(List<AttendAuditManagerSetResult> list){
        Date date = new Date();
        Long attendAuditId = null;
        for(int i=0;i<list.size();i++){
            List<AttendDismissed> list2 = list.get(i).getAttendDismissedList();
            for(int j=0;j<list2.size();j++){
                AttendDismissed attendDismissed = list2.get(j);

                if(i ==0 && j == 0 ){
                    date = attendDismissed.getDismissedTime();
                    attendAuditId = attendDismissed.getAttendAudit();
                }

                if(!attendDismissed.getAttendAudit().equals(attendAuditId)){

                    date = attendDismissed.getDismissedTime();
                    attendAuditId = attendDismissed.getAttendAudit();
                }

                if(i > 0){
                    if(date.getTime() == list2.get(j).getDismissedTime().getTime()){

                    }else{
                        list2.get(j).setDismissedNote("");
                        list2.get(j).setDismissedTime(null);
                    }
                }
                if(j > 0){
                    list2.get(j).setDismissedNote("");
                    list2.get(j).setDismissedTime(null);
                }
            }

        }
        return list;
    }

    /**
     * （店长考勤修改页面）编辑员工的出勤天数，公休天数，应发工资数，是否在职，是否发工资信息，以及备注1
     *
     *
     * @author wjk
     * @Date 2021-09-17
     * 增加验证，店长手机号，增加修改gw,gz,zw
     * updateDate 2021-11-08
     */
    @Override
    public boolean updateAttendEmployeeMonthById(AttendEmployeeMonthParam attendEmployeeMonthParam,String account) {

        // 根据店长手机号获取店长当月的考勤信息
        AttendAudit attendAudit = attendAuditService.getAttendAuditByDzPhone(account);

        //当月考勤的店的信息，则返回修改失败
        if(ToolUtil.isEmpty(attendAudit)){
            return false;
        }
        //若信息的提交状态为已提交，或者信息已经通过督导的审核，则不允许修改相关信息
        if(attendAudit.getAuditStatus().equals(String.valueOf(AttendAuditStatusEnum.SUBMIT_AUDIT.getCode()))||attendAudit.getAuditStatus().equals(String.valueOf(AttendAuditStatusEnum.SUBMIT_THROUGH.getCode()))){
            return false;
        }

        //除去id,出勤天数，公休天数，  应发工资数，是否在职，是否发工资信息，以及备注1，其他值赋值为空
        AttendEmployeeMonthParam parm = new AttendEmployeeMonthParam();
        parm.setId(attendEmployeeMonthParam.getId());

        //查询员工的旧的信息
        AttendEmployeeMonth oldEntity = getOldEntity(parm);

        //根据银行卡的基本信息判断 
        Map<String,String> mapYhkInfo = getYhkInfo(attendEmployeeMonthParam.getYhk());

        // 判断银行卡状态，为空，或者银行卡状态为异常则允许修改银行卡信息
        // 1.银行卡状态为空的允许修改
        // 2.银行卡状态为2的允许修改
        // 3.非人事同步过来数据可以修改(店长新加员工和钉钉同步的员工)
        // 4.人事同事新加的员工允许修改数据
        // 5.钉钉同步过来员工允许修改数据
        if(ToolUtil.isEmpty(oldEntity.getYhkStatus())||String.valueOf(oldEntity.getYhkStatus()).equals("2")||!"0".equals(String.valueOf(oldEntity.getSynchronousStatus()))||"1".equals(oldEntity.getBtyArchicesNewEmp())||(ToolUtil.isNotEmpty(oldEntity.getDingdingNewEmp())&&oldEntity.getDingdingNewEmp().equals("T"))){

            if(mapYhkInfo.get("flag").equals("true")){
                parm.setYhk(mapYhkInfo.get("yhk"));
                parm.setBank(mapYhkInfo.get("bank"));
                parm.setHh(mapYhkInfo.get("hh"));
                parm.setCardName(mapYhkInfo.get("cardName"));
                parm.setYhkStatus(Integer.valueOf(mapYhkInfo.get("yhkStatus")));
            }
        }

        //若没有查询到员工旧的信息，返回修改失败
        if(ToolUtil.isEmpty(oldEntity)){
            return false;
        }

        //若店长考勤的店和该员工不是一条对应的考勤信息，则不允许修改该员工信息
        if(!attendAudit.getId().equals(oldEntity.getAttendAuditId())){
            return false;
        }

        //修改在职状态
        parm.setZtNew(attendEmployeeMonthParam.getZtNew());
        //修改是否应发工资
        parm.setPayWage(attendEmployeeMonthParam.getPayWage());
        //若职位不为空，并且员工为督导或营运经理 ，则默认在职，并且不能修改
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getZw())){
            if(attendEmployeeMonthParam.getZw().equals(EmployeePositionEnum.POSITION20.getMsg())||attendEmployeeMonthParam.getZw().equals(EmployeePositionEnum.POSITION21.getMsg())){
                //修改在职状态
                parm.setZtNew(0);
                //修改是否应发工资
                parm.setPayWage(0);

                //修改在职状态
                attendEmployeeMonthParam.setZtNew(0);
                //修改是否应发工资
                attendEmployeeMonthParam.setPayWage(0);
            }
        }

        //修改店长备注信息
        parm.setManagerNote(attendEmployeeMonthParam.getManagerNote());

        //修改考勤天数
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getHolidayDays())&&attendEmployeeMonthParam.getHolidayDays() < 0.00001){
            parm.setHolidayDays(Float.valueOf("0"));
            attendEmployeeMonthParam.setHolidayDays(Float.valueOf("0"));
        }else{
            parm.setHolidayDays(attendEmployeeMonthParam.getHolidayDays());
        }
        //修改公休天数
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getAttendanceDays())&&attendEmployeeMonthParam.getAttendanceDays() < 0.00001){
            parm.setAttendanceDays(Float.valueOf("0"));
            attendEmployeeMonthParam.setAttendanceDays(Float.valueOf("0"));
        }else{
            parm.setAttendanceDays(attendEmployeeMonthParam.getAttendanceDays());
        }
        //确定，旧的职位和新的职位信息必须在店助的信息以下，则允许修改，若，在店助以上则不允许修改信息
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getZw())){
            //原来职位为空，或者职位在允许修改职位的列表里
            if(ToolUtil.isEmpty(oldEntity.getZw())){
                //修改职位
                parm.setZw(attendEmployeeMonthParam.getZw());
            }else{
                if(EmployeePositionEnum.POSITIONALL.getMsg().indexOf(oldEntity.getZw())>-1&&EmployeePositionEnum.POSITIONALL.getMsg().indexOf(attendEmployeeMonthParam.getZw())>-1){

                    //修改职位
                    parm.setZw(attendEmployeeMonthParam.getZw());
                    //若改动职位相同，则不用修改职位
                    if(parm.getZw().equals(oldEntity.getZw())){

                    }else{
                        parm.setZwOld(oldEntity.getZw());
                    }
                }
                //还有处理，员工，储备，小时工
                if(oldEntity.getZw().equals("员工")&&EmployeePositionEnum.POSITIONALL.getMsg().indexOf(attendEmployeeMonthParam.getZw())>-1){
                    //修改职位
                    parm.setZw(attendEmployeeMonthParam.getZw());
                    parm.setZwOld(oldEntity.getZw());
                }
                //还有处理，员工，储备，小时工
                if(oldEntity.getZw().equals("储备")&&EmployeePositionEnum.POSITIONALL.getMsg().indexOf(attendEmployeeMonthParam.getZw())>-1){
                    //修改职位
                    parm.setZw(attendEmployeeMonthParam.getZw());
                    parm.setZwOld(oldEntity.getZw());
                }
                //还有处理，员工，储备，小时工
                if(oldEntity.getZw().equals("小时工")&&EmployeePositionEnum.POSITIONALL.getMsg().indexOf(attendEmployeeMonthParam.getZw())>-1){
                    //修改职位
                    parm.setZw(attendEmployeeMonthParam.getZw());
                    parm.setZwOld(oldEntity.getZw());
                }
            }

        }
        //只有是人资添加的新员工，或者是新员工的才可以修改，或者是钉钉新加的员工
        if("1".equals(oldEntity.getBtyArchicesNewEmp())||!"0".equals(String.valueOf(oldEntity.getSynchronousStatus()))||(ToolUtil.isNotEmpty(oldEntity.getDingdingNewEmp())&&oldEntity.getDingdingNewEmp().equals("T"))){
            //修改gz
            parm.setGz(attendEmployeeMonthParam.getGz());
            //修改gw
            parm.setGw(attendEmployeeMonthParam.getGw());
        }

        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getBtyArchicesId())){
            //获取旧的员工信息，若旧的员工职位和新的员工职位相等，工资不允许修改，赋值原来的数值！
            String positionFormal =  "迎宾,前厅员工,后厨员工,员工,储备";
            String positionNotFormal = "钟点工,兼职,小时工";

            AttendAuditBtyArchivesParam attendAuditBtyArchives = new AttendAuditBtyArchivesParam();
            attendAuditBtyArchives.setId(attendEmployeeMonthParam.getBtyArchicesId().intValue());
            AttendAuditBtyArchives attendAuditBtyArchivesOld =  attendAuditBtyArchivesService.detailById(attendAuditBtyArchives);
            //若查询出的旧的员工和赋值的职位计算方式相同，并且原来工资不为0，则赋值，工资到现有的人员中
            if(ToolUtil.isNotEmpty(attendAuditBtyArchivesOld)){
                //同属于正式员工，则判断人事工资不为空的情况下不为空的情况下，工资赋予原来人事档案中的值；
                if(positionFormal.indexOf(attendEmployeeMonthParam.getZw())>-1&&positionFormal.indexOf(attendAuditBtyArchivesOld.getZw())>-1){
                    BigDecimal bigDecimalZero = new BigDecimal("0");
                    //人事档案工资为0允许店长修改工资，其他时候赋值工资为原人事档案的薪资；
                    if((attendAuditBtyArchivesOld.getGz().compareTo(bigDecimalZero) == 0) &&(attendAuditBtyArchivesOld.getGw().compareTo(bigDecimalZero) == 0)){
                        parm.setGz(attendEmployeeMonthParam.getGz());
                        parm.setGw(attendEmployeeMonthParam.getGw());
                    }else{
                        parm.setGz(attendAuditBtyArchivesOld.getGz());
                        parm.setGw(attendAuditBtyArchivesOld.getGw());
                    }
                }


//                //同属于非正式员工，则判断他们不为空的情况下，工资赋予原来人事档案中的值
//                if(positionNotFormal.indexOf(attendEmployeeMonthParam.getZw())>-1&&positionNotFormal.indexOf(attendAuditBtyArchivesOld.getZw())>-1){
//                    BigDecimal bigDecimalZero = new BigDecimal("0");
//                    //人事档案工资为0允许店长修改工资，其他时候赋值工资为原人事档案的薪资；
//                    if((attendAuditBtyArchivesOld.getGz().compareTo(bigDecimalZero) == 0)){
//                        parm.setGz(attendEmployeeMonthParam.getGz());
//                        parm.setGw(bigDecimalZero);
//                    }else{
//                        parm.setGz(attendAuditBtyArchivesOld.getGz());
//                        parm.setGw(attendAuditBtyArchivesOld.getGw());
//                    }
//                }


                //同属于非正式员工，则判断他们不为空的情况下，
                // 若职位相等，则判断修改工资为人事的工资
                // 若职位不想等，则允许修改工资
                if(positionNotFormal.indexOf(attendEmployeeMonthParam.getZw())>-1&&positionNotFormal.indexOf(attendAuditBtyArchivesOld.getZw())>-1){
                    BigDecimal bigDecimalZero = new BigDecimal("0");
                    //人事档案工资为0允许店长修改工资，
                    if((attendAuditBtyArchivesOld.getGz().compareTo(bigDecimalZero) == 0)){
                        parm.setGz(attendEmployeeMonthParam.getGz());
                        parm.setGw(bigDecimalZero);
                    }

                    //人事档案中的职位和修改的职位 --- 不相等，允许店长修改工资
                    if(!attendEmployeeMonthParam.getZw().equals(attendAuditBtyArchivesOld.getZw())){
                        parm.setGz(attendEmployeeMonthParam.getGz());
                        parm.setGw(bigDecimalZero);
                    }
                    //人事档案中的职位和修改的职位 --- 相等，并且是人事认定的老员工，不允许店长修改工资
                    if(attendEmployeeMonthParam.getZw().equals(attendAuditBtyArchivesOld.getZw())&&!"1".equals(oldEntity.getBtyArchicesNewEmp())){
                        parm.setGz(attendAuditBtyArchivesOld.getGz());
                        parm.setGw(attendAuditBtyArchivesOld.getGw());
                    }
                }

                //人事档案中，为正式的员工，新修改为非正式i员工的，允许修改基本工资，岗位工资为0
                if(positionNotFormal.indexOf(attendEmployeeMonthParam.getZw())>-1&&positionFormal.indexOf(attendAuditBtyArchivesOld.getZw())>-1){
                    BigDecimal bigDecimalZero = new BigDecimal("0");
                    parm.setGz(attendEmployeeMonthParam.getGz());
                    parm.setGw(bigDecimalZero);
                }
                //人事档案中，为非正式的员工，新修改为正式员工的，允许修改基本工资，岗位工资
                if(positionFormal.indexOf(attendEmployeeMonthParam.getZw())>-1&&positionNotFormal.indexOf(attendAuditBtyArchivesOld.getZw())>-1){
                    BigDecimal bigDecimalZero = new BigDecimal("0");
                    parm.setGz(attendEmployeeMonthParam.getGz());
                    parm.setGw(attendEmployeeMonthParam.getGw());
                }

            }
        }



        //钉钉添加的新员工，或者是新员工的才可以修改sfz,yhk,

        if((ToolUtil.isNotEmpty(oldEntity.getDingdingNewEmp())&&oldEntity.getDingdingNewEmp().equals("T"))||!"0".equals(String.valueOf(oldEntity.getSynchronousStatus()))){
            //修改Sfz
            parm.setSfz(attendEmployeeMonthParam.getSfz());
        }

        //根据修改的信息计算应发工资数
        AttendAuditManagerSetResult attendAuditManagerSetResultOld = new AttendAuditManagerSetResult();

        //若考勤月份为空，则为新员工，当月进行考勤
        if(ToolUtil.isEmpty(attendEmployeeMonthParam.getAttendMonth())){
            // 获取当前要考勤的月份
            Map<String,String> map = attendAuditBtyArchivesService.intoAttendEmployeeMonthListValidationParam(null,null);
            String attendMonth = map.get("attendMonth").replaceAll("-","");
            attendEmployeeMonthParam.setAttendMonth(attendMonth);
        }

        ToolUtil.copyProperties(attendEmployeeMonthParam, attendAuditManagerSetResultOld);

        AttendAuditManagerSetResult  attendAuditManagerSetResultNew = calculateEmployeeSalary(attendAuditManagerSetResultOld, "");
        parm.setShouldPay(attendAuditManagerSetResultNew.getShouldPay());

        //若，确认不发工资，则设置相关数据 出勤天数，公休天数，应发工资数为0
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getPayWage())){
            if(attendEmployeeMonthParam.getPayWage() == 1){
                parm.setHolidayDays(Float.valueOf("0"));
                parm.setAttendanceDays(Float.valueOf("0"));
                parm.setShouldPay(BigDecimal.ZERO);
            }
        }else{
            //为空的，默认发工资
            attendEmployeeMonthParam.setPayWage(0);
        }


        String positionNotFormal = "钟点工,兼职,小时工";
        //若是兼职，钟点工，小时工，
        //则将gw工资清零
        if(ToolUtil.isNotEmpty(parm.getZw())){
            if(positionNotFormal.indexOf(parm.getZw())>-1){
                BigDecimal bigDecimalZero = new BigDecimal("0");
                parm.setGw(bigDecimalZero);
            }
        }

        AttendEmployeeMonth newEntity = getEntity(parm);
        //更新相关数据
        //ToolUtil.copyProperties(newEntity, oldEntity);
        boolean flag = this.updateById(newEntity);
        //若，确认发工资，并且原来的数据，是不发工资则 清空相关数据（出勤天数，公休天数，  应发工资数为null）
        if(attendEmployeeMonthParam.getPayWage() == 0 && oldEntity.getPayWage() == 1){
            AttendEmployeeMonth attendEmployeeMonth = new AttendEmployeeMonth();
            attendEmployeeMonth.setId(attendEmployeeMonthParam.getId());
            parm.setHolidayDays(null);
            parm.setAttendanceDays(null);
            parm.setShouldPay(null);
            //根据员工的id 清空相关数据（出勤天数，公休天数，  应发工资数为null）
            int size = this.baseMapper.updateDayById(attendEmployeeMonth);
        }
        return flag;
    }

    /**
     * （店长考勤修改页面+新增员工信息）增加员工信息的验证消息
     * @param attendEmployeeMonthParam
     * @param account
     * @return
     * @author wjk
     * @Date 2021-10-08
     */
    @Override
    public AttendEmployeeMonthAddValidationResult addAttendEmployeeMonthValidation(AttendEmployeeMonthParam attendEmployeeMonthParam, String account){
        AttendEmployeeMonthAddValidationResult  result = new AttendEmployeeMonthAddValidationResult();
        Map<String,String> map = new HashMap<String,String>();
        result.setFlag("true");
        //当flag = false 的时候同步buttonInfo，buttonState 生效 buttonState 0，信息不全,1 为“同步”，2为“调店”，3.钉钉中的数据"同步"



        AttendAuditBtyArea attendAuditBtyArea =  this.attendAuditBtyAreaService.getShopInfoByDzPhone(account);
        //***第一种情况
        //若电话号码或者身份证都为空则返回
        if(ToolUtil.isEmpty(attendEmployeeMonthParam.getSfz())&&ToolUtil.isEmpty(attendEmployeeMonthParam.getTel())){
            result.setFlag("false");
            result.setMessage("信息无法判断");
            result.setButtonState("0");
            return result;
        }

        //***第二种情况
        //查找改员工是否是在本月考勤的店铺中，若有则选择调店信息
        AttendAuditManagerSetResult attendAuditManagerSetResult = new AttendAuditManagerSetResult();

        AttendAuditManagerSetParam attendAuditManagerSetParam = new AttendAuditManagerSetParam();
        //参数中attendMonth 不能为空！！
        attendAuditManagerSetParam = attendMonthIsNotNullForDz(attendAuditManagerSetParam);
        attendAuditManagerSetResult.setAttendMonth(attendAuditManagerSetParam.getAttendMonth());

        // 判断手机号位数正确，则
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getTel())&&attendEmployeeMonthParam.getTel().length() == 11){
            attendAuditManagerSetResult.setTel(attendEmployeeMonthParam.getTel());
        }
        // 判断身份证位数正确
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getSfz())&&attendEmployeeMonthParam.getSfz().length() == 18 ){
            attendAuditManagerSetResult.setSfz(attendEmployeeMonthParam.getSfz());
        }


        List<AttendAuditManagerSetResult> attendAuditManagerSetResultList =  this.baseMapper.getEmployeeListMonthByEmployeeInfo(attendAuditManagerSetResult);
        if(attendAuditManagerSetResultList.size()>0){
            AttendAuditManagerSetResult attendAuditManagerSetResultOld = attendAuditManagerSetResultList.get(0);
            //是一家店，提示同步,不是一家店，提示调店，是一家店的也要求他选择调店
            if(attendAuditManagerSetResultOld.getDm().equals(attendAuditBtyArea.getDm())){
//                map.put("flag","false");
//                map.put("message","员工 "+attendAuditManagerSetResultOld.getDm()+" 的档案在 "+attendAuditManagerSetResultOld.getXm()+" ，不允许添加新员工，请选择调店。");
//                map.put("buttonState","2");
//                map.put("id",String.valueOf(attendAuditManagerSetResultOld.getBtyArchicesId()));
//                return map;
                result.setFlag("false");
                result.setMessage("员工 "+attendAuditManagerSetResultOld.getXm()+" 的档案在 "+attendAuditManagerSetResultOld.getDm()+" ，不允许添加新员工，请选择调店。");
                result.setButtonState("2");
                result.setDmState("1");
                result.setDm(attendAuditManagerSetResultOld.getDm());
                result.setXm(attendAuditManagerSetResultOld.getXm());
                result.setId(attendAuditManagerSetResultOld.getBtyArchicesId());
                return result;
            }else{
//                map.put("flag","false");
//                map.put("message","员工 "+attendAuditManagerSetResultOld.getXm()+" 的档案在 "+attendAuditManagerSetResultOld.getDm()+",不允许添加新员工，请选择调店。");
//                map.put("buttonState","2");
//                return map;
                result.setFlag("false");
                result.setMessage("员工 "+attendAuditManagerSetResultOld.getXm()+" 的档案在 "+attendAuditManagerSetResultOld.getDm()+" ，不允许添加新员工，请选择调店。");
                result.setButtonState("2");
                result.setId(attendAuditManagerSetResultOld.getBtyArchicesId());
                result.setDmState("2");
                result.setDm(attendAuditManagerSetResultOld.getDm());
                result.setXm(attendAuditManagerSetResultOld.getXm());
                return result;
            }

        }


        //***第三种情况
        //查找员工是否在员工档案中，若和店长是一家店，则返回同步，若和店长不是一家店则返回调店信息

        AttendAuditBtyArchives attendAuditBtyArchives = new AttendAuditBtyArchives();

        //***第三种情况的情况2
        //若电话号码不为空
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getTel())){
            attendAuditBtyArchives = this.attendAuditBtyArchivesService.getOneByPhone(attendEmployeeMonthParam.getTel());
            //若能查询到员工信息
            if(ToolUtil.isNotEmpty(attendAuditBtyArchives)&&ToolUtil.isNotEmpty(attendAuditBtyArchives.getId())){
                //判断这个员工是否和店长考勤的店是否是一家店
                //是一家店，提示同步,不是一家店，提示调店
                if(attendAuditBtyArchives.getDm().equals(attendAuditBtyArea.getDm())){
//                    map.put("flag","false");
//                    map.put("message","人事在 "+attendAuditBtyArchives.getDm()+"，已经添加员工 "+attendAuditBtyArchives.getXm()+" ，请同步员工考勤信息。");
//                    map.put("buttonState","1");
//                    map.put("bh",attendAuditBtyArchives.getBh());
//                    return map;
                    result.setFlag("false");
                    result.setMessage("人事在 "+attendAuditBtyArchives.getDm()+"，已经添加员工 "+attendAuditBtyArchives.getXm()+" ，请同步员工考勤信息。");
                    result.setButtonState("1");
                    result.setBh(attendAuditBtyArchives.getBh());
                    result.setDmState("1");
                    result.setDm(attendAuditBtyArchives.getDm());
                    result.setXm(attendAuditBtyArchives.getXm());
                    return result;
                }else{
//                    map.put("flag","false");
//                    map.put("message","员工 "+attendAuditBtyArchives.getXm()+" 的档案在 "+attendAuditBtyArchives.getDm()+",不允许添加新员工，请选择调店。");
//                    map.put("buttonState","2");
//                    map.put("id",String.valueOf(attendAuditBtyArchives.getId()));
//                    return map;
                    result.setFlag("false");
                    result.setMessage("员工 "+attendAuditBtyArchives.getXm()+" 的档案在 "+attendAuditBtyArchives.getDm()+" ，不允许添加新员工，请选择调店。");
                    result.setButtonState("2");
                    result.setId(Long.valueOf(attendAuditBtyArchives.getId()));
                    result.setDmState("2");
                    result.setDm(attendAuditBtyArchives.getDm());
                    result.setXm(attendAuditBtyArchives.getXm());
                    return result;
                }
            }
        }

        //***第三种情况的情况1
        //若身份证为不为空
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getSfz())&&attendEmployeeMonthParam.getSfz().length() == 18){
            attendAuditBtyArchives = this.attendAuditBtyArchivesService.getOneBySfz(attendEmployeeMonthParam.getSfz());
            //若能查询到员工信息
            if(ToolUtil.isNotEmpty(attendAuditBtyArchives)&&ToolUtil.isNotEmpty(attendAuditBtyArchives.getId())){
                //判断这个员工是否和店长考勤的店是否是一家店
                //是一家店，提示同步,不是一家店，提示调店
                if(attendAuditBtyArchives.getDm().equals(attendAuditBtyArea.getDm())){
//                    map.put("flag","false");
//                    map.put("message","人事在 "+attendAuditBtyArchives.getDm()+"，已经添加员工 "+attendAuditBtyArchives.getXm()+" ，请同步员工考勤信息。");
//                    map.put("buttonState","1");
//                    map.put("bh",attendAuditBtyArchives.getBh());
//                    return map;
                    result.setFlag("false");
                    result.setMessage("人事在 "+attendAuditBtyArchives.getDm()+"，已经添加员工 "+attendAuditBtyArchives.getXm()+" ，请同步员工考勤信息。");
                    result.setButtonState("1");
                    result.setBh(attendAuditBtyArchives.getBh());
                    result.setDm(attendAuditBtyArchives.getDm());
                    result.setXm(attendAuditBtyArchives.getXm());
                    return result;
                }else{
//                    map.put("flag","false");
//                    map.put("message","员工 "+attendAuditBtyArchives.getXm()+" 的档案在 "+attendAuditBtyArchives.getDm()+",不允许添加新员工，请选择调店。");
//                    map.put("buttonState","2");
//                    map.put("id",String.valueOf(attendAuditBtyArchives.getId()));
//                    return map;
                    result.setFlag("false");
                    result.setMessage("员工 "+attendAuditBtyArchives.getDm()+" 的档案在 "+attendAuditBtyArchives.getXm()+" ，不允许添加新员工，请选择调店。");
                    result.setButtonState("2");
                    result.setId(Long.valueOf(attendAuditBtyArchives.getId()));
                    result.setDm(attendAuditBtyArchives.getDm());
                    result.setXm(attendAuditBtyArchives.getXm());
                    return result;
                }
            }
        }

        //***第四种情况
        //若上面考勤信息中，和档案中没有，则查找钉钉中的数据，若有,则返回从钉钉查找到的数据bh
        List<AttendAuditManagerSetResult> sysEmpList =  this.baseMapper.getAttendEmployeeMonthSysEmp(attendAuditManagerSetResult);
        if(sysEmpList.size()>0){
            AttendAuditManagerSetResult sysEmp= sysEmpList.get(0);
            //判断从钉钉中找到此员工了
            if(ToolUtil.isNotEmpty(sysEmp)&&ToolUtil.isNotEmpty(sysEmp.getBh())){
//                map.put("flag","false");
//                map.put("message","员工 "+sysEmp.getXm()+" 在钉钉中存在，请同步钉钉。");
//                map.put("buttonState","3");
//                map.put("bh",sysEmp.getBh());
//                return map;
                result.setFlag("false");
                result.setMessage("员工 "+sysEmp.getXm()+" 在钉钉中存在，请同步钉钉。");
                result.setButtonState("3");
                result.setBh(sysEmp.getBh());
                result.setDm(sysEmp.getDm());
                result.setXm(sysEmp.getXm());
                return result;
            }
        }
        return result;
    }
    /**
     * （店长考勤修改页面+新增员工信息） 根据编号，和同步状态，同步单个考勤信息
     * @param account
     * @return
     */
    @Override
    public AttendEmployeeMonth synchronousOneAttendEmployeeMonthByBh(String account,AttendEmployeeMonthAddValidationResult attendEmployeeMonthAddValidationResult){

        // 获取当前要考勤的月份
        Map<String,String> map = attendAuditBtyArchivesService.intoAttendEmployeeMonthListValidationParam(null,null);
        String attendMonth = map.get("attendMonth").replaceAll("-","");

        AttendEmployeeMonth attendEmployeeMonth = new AttendEmployeeMonth();

        String buttonState = attendEmployeeMonthAddValidationResult.getButtonState();
        String bh = attendEmployeeMonthAddValidationResult.getBh();

        AttendEmployeeMonth attendEmployeeMonthOld = new AttendEmployeeMonth();
        attendEmployeeMonthOld.setBh(bh);

        //判断是钉钉员工还是人事同事的员工
        //需要根据编号从钉钉数据中获取到数据
        if(buttonState.equals("3")){
            List<AttendEmployeeMonth> attendEmployeeMonthList = this.baseMapper.getAttendEmployeeMonthSysEmpByBh(attendEmployeeMonthOld);
            if(attendEmployeeMonthList.size()>0){
                attendEmployeeMonthOld = attendEmployeeMonthList.get(0);

            }
        }
        //需要根据编号从人事中获取数据
        if(buttonState.equals("1")){
            List<AttendEmployeeMonth> attendEmployeeMonthList = this.attendAuditBtyArchivesService.getAttendEmployeeMonthAuditBtyAreaServiceByBh(attendEmployeeMonthOld);
            if(attendEmployeeMonthList.size()>0){
                attendEmployeeMonthOld = attendEmployeeMonthList.get(0);
            }
        }
        //若获取到的电话为空，则返回空数据
        if(ToolUtil.isEmpty(attendEmployeeMonthOld.getTel())){
            return attendEmployeeMonth;
        }
        //根据手机号，再验证一遍，有没有员工信息被重复插入了，
        AttendEmployeeMonthParam attendEmployeeMonthParam = new AttendEmployeeMonthParam();
        ToolUtil.copyProperties(attendEmployeeMonthOld,attendEmployeeMonthParam);
        AttendEmployeeMonthAddValidationResult result = addAttendEmployeeMonthValidation( attendEmployeeMonthParam,account);

        //若,返回的验证不是是调店，则判断是不是在本店中,若是在本店中并且可以查询到数据，则可直接返回本店查询到的数据
        if(result.getButtonState().equals("2")){
            if(ToolUtil.isNotEmpty(result.getDmState())&&result.getDmState().equals("1")){
                AttendAuditManagerSetResult attendAuditManagerSetResult = new AttendAuditManagerSetResult();
                ToolUtil.copyProperties(attendEmployeeMonthOld,attendAuditManagerSetResult);
                attendAuditManagerSetResult.setAttendMonth(attendMonth);
                List<AttendAuditManagerSetResult> attendAuditManagerSetResultList =  this.baseMapper.getEmployeeListMonthByEmployeeInfo(attendAuditManagerSetResult);
                if(attendAuditManagerSetResultList.size()>0) {
                    AttendAuditManagerSetResult attendAuditManagerSetResultOld = attendAuditManagerSetResultList.get(0);
                    ToolUtil.copyProperties(attendAuditManagerSetResultOld,attendEmployeeMonth);
                    return attendEmployeeMonth;
                }
            }

        }

        //若 返回的验证不是同步，则返回
        if(result.getButtonState().equals("1")||result.getButtonState().equals("3")){

        }else{
            return attendEmployeeMonth;
        }



        //考勤的月份
        attendEmployeeMonthOld.setAttendMonth(attendMonth);
        //同步的月份
        attendEmployeeMonthOld.setSynchronousMonth(sdf.format(new Date()));
        //是否发工资为发
        attendEmployeeMonthOld.setPayWage(0);
        //在职状态为在职
        attendEmployeeMonthOld.setZtNew(0);
        //判断获取的数据在档案中没有，需要从人事档案中获取则执行
        if(result.getFlag().equals("false")&&result.getButtonState().equals("1")&&ToolUtil.isNotEmpty(attendEmployeeMonthOld.getBtyArchicesId())){
            attendEmployeeMonthOld.setId(Long.valueOf(attendMonth+String.valueOf(attendEmployeeMonthOld.getBtyArchicesId())));
            attendEmployeeMonthOld.setSynchronousStatus(0);
        }

        //判断获取的数据在档案中没有，需要从钉钉档案中获取则执行
        if(result.getFlag().equals("false")&&result.getButtonState().equals("3")){
            Long id = UUIDUtils.getId();
            attendEmployeeMonthOld.setId(Long.valueOf(sdfs.format(new Date())+String.valueOf(id).substring(12,13)));
            attendEmployeeMonthOld.setBtyArchicesId(Long.valueOf(sdfs.format(new Date()).substring(5,12)+String.valueOf(id).substring(12,13)));
            //新员工状态
            attendEmployeeMonthOld.setSynchronousStatus(1);
            //钉钉同步为同步
            attendEmployeeMonthOld.setDingdingNewEmp("T");
            //原有状态为zt
            attendEmployeeMonthOld.setZt(0);
            //区域，取店长所在的区域信息
            //获取店长的信息
            AttendAuditBtyArchives attendAuditBtyArchivesdz  = attendAuditBtyArchivesService.getOneByPhone(account);
            attendEmployeeMonthOld.setQy(attendAuditBtyArchivesdz.getQy());
            attendEmployeeMonthOld.setEqy(attendAuditBtyArchivesdz.getEqy());
            //gz默认为0，gw默认为0
            attendEmployeeMonthOld.setGz(new BigDecimal("0"));
            attendEmployeeMonthOld.setGw(new BigDecimal("0"));

        }
        //根据店长电话获取店长的信息；
        AttendAuditBtyArchives attendAuditBtyArchivesdd = attendAuditBtyArchivesService.getOneByPhone(account);
        //查询这个店这个月的考勤信息
        AttendAudit attendAuditOld = this.attendAuditService.getById(Long.valueOf(attendMonth+attendAuditBtyArchivesdd.getId()));
        //查询这个员工，应该在那个店进行考勤的信息；
        attendEmployeeMonthOld.setAttendAuditId(attendAuditOld.getId());
        attendEmployeeMonthOld.setDm(attendAuditOld.getDm());
        //单条数据的插入信息
        boolean falg = this.save(attendEmployeeMonthOld);
        if(falg){
            //根据编号信息查询相应的信息
            attendEmployeeMonth = getAttendEmployeeMonthByBh(attendEmployeeMonthOld,attendMonth);
        }

        return attendEmployeeMonth;

    }

    /**
     * 根据编号查询
     * @param attendEmployeeMonthOld
     * @return
     */
    private AttendEmployeeMonth getAttendEmployeeMonthByBh(AttendEmployeeMonth attendEmployeeMonthOld,String attendMonth) {
        AttendEmployeeMonth attendEmployeeMonth = new AttendEmployeeMonth();
        //根据编号获取，该店下的员工档案信息(考勤月);
        LambdaQueryWrapper<AttendEmployeeMonth> queryWrapper = new LambdaQueryWrapper<AttendEmployeeMonth>();
        queryWrapper.eq(AttendEmployeeMonth::getAttendMonth,attendMonth);
        queryWrapper.eq(AttendEmployeeMonth::getBh,attendEmployeeMonthOld.getBh());
        List<AttendEmployeeMonth> list = this.list(queryWrapper);
        if(list.size()>0){
            attendEmployeeMonth = list.get(0);
        }
        return  attendEmployeeMonth;
    }
    /**
     * 根据编号查询
     * @param attendEmployeeMonthOld
     * @return
     */
    private AttendEmployeeMonth getAttendEmployeeMonthByBhOneYyjl(AttendEmployeeMonth attendEmployeeMonthOld,String attendMonth,AttendAuditBtyArea attendAuditBtyArea){
        AttendEmployeeMonth attendEmployeeMonth = new AttendEmployeeMonth();
        //根据编号获取，该店下的员工档案信息(考勤月);
        LambdaQueryWrapper<AttendEmployeeMonth> queryWrapper = new LambdaQueryWrapper<AttendEmployeeMonth>();
        queryWrapper.eq(AttendEmployeeMonth::getAttendMonth,attendMonth);
        queryWrapper.eq(AttendEmployeeMonth::getBh,attendEmployeeMonthOld.getBh());
        List<AttendEmployeeMonth> list = this.list(queryWrapper);



        if(list.size()>0){
            AttendEmployeeMonth attendEmployeeMonthEmp = list.get(0);
            if(ToolUtil.isNotEmpty(attendEmployeeMonthOld.getAttendAuditId())){
                AttendAudit attendAudit = new AttendAudit();
                attendAudit.setId(attendEmployeeMonthOld.getAttendAuditId());
                AttendAudit attendAuditEmp = this.attendAuditService.getById(attendAudit);
                AttendAuditBtyArea attendAuditBtyAreaEmp = this.attendAuditBtyAreaService.getShopInfoByDzPhone(attendAuditEmp.getManagerPhone());

                //若是相同的营运经理，则将数据返回，若不是相同的营运经理，则返回空
                if(attendAuditBtyAreaEmp.getYyjl().equals(attendAuditBtyArea.getYyjl())){
                    attendEmployeeMonth =attendEmployeeMonthEmp;
                }

            }
        }

        return  attendEmployeeMonth;
    }

    /**
     * （店长考勤修改页面+新增员工信息） 增加员工信息
     *
     *
     * @author wjk
     * @Date 2021-09-17
     */
    @Override
    public boolean addAttendEmployeeMonth(AttendEmployeeMonthParam attendEmployeeMonthParam,String account) {

        AttendEmployeeMonthAddValidationResult mapValidation = addAttendEmployeeMonthValidation(attendEmployeeMonthParam,account);
        //若等于false,则只允许钉钉添加的员工进行添加数据
        if(mapValidation.getFlag().equals("false")){
            if(!mapValidation.getButtonState().equals("3")){
                return false;
            }
        }

        System.out.println(attendEmployeeMonthParam.toString());
        //根据店长的手机号获取他的提交信息
        AttendAudit attendAudit = attendAuditService.getAttendAuditByDzPhone(account);
        AttendEmployeeMonth entity = getEntity(attendEmployeeMonthParam);
        Long id = UUIDUtils.getId();
        entity.setId(Long.valueOf(sdfs.format(new Date())+String.valueOf(id).substring(12,13)));
        entity.setBtyArchicesId(Long.valueOf(sdfs.format(new Date()).substring(5,12)+String.valueOf(id).substring(12,13)));
        //员工状态为新增
        entity.setSynchronousStatus(AttendEmployeeSynchronousStatusEnum.NEW_EMPLOYEE_NOT_SUBMIT.getCode());

        //获取银行简称
        String bank = this.getYhCode(attendEmployeeMonthParam.getYhk());
        //通过银行简称获取行号
        String code = btyBxdaService.getBankCode(bank);

        entity.setBank(bank);
        entity.setHh(code);

        //默认取当前的日期，若传过来的日期不为空，则日期取传过来的日期
        entity.setRq(new Date());
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getRq())){
            entity.setRq(attendEmployeeMonthParam.getRq());
        }
        entity.setYhkStatus(1);
        entity.setZt(0);
        //考勤月份

        Map<String,String> map = this.attendAuditService.getAttendMonth();
        String attendMonthStr = map.get("attendMonth").replaceAll("-","");

        entity.setAttendMonth(attendMonthStr);

        entity.setSynchronousMonth(sdf.format(new Date()));
        entity.setPayWage(0);
        entity.setZtNew(0);
        entity.setAttendAuditId(attendAudit.getId());
        //身份证
        entity.setSfz(attendEmployeeMonthParam.getSfz());


        //根据店长的手机号获取店长的信息
        AttendAuditBtyArchives attendAuditBtyArchivesDz = this.attendAuditBtyArchivesService.getOneByPhone(account);
        //区域信息取店长信息的区域！
        entity.setQy(attendAuditBtyArchivesDz.getQy());
        entity.setEqy(attendAuditBtyArchivesDz.getEqy());

        //若是钉钉过来的新员工，则有编号信息，若不是钉钉过来的新员工，则手机号默认是他的编号；
        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getBh())){
            entity.setBh(attendEmployeeMonthParam.getBh());
        }else{
            entity.setBh(attendEmployeeMonthParam.getTel());
        }
        return this.save(entity);
     }

    /**
     * （店长考勤修改页面+修改新增员工信息） 修改员工信息
     *
     *
     * @author wjk
     * @Date 2021-09-17
     */
    @Override
    public boolean updateAttendEmployeeMonth(AttendEmployeeMonthParam param) {
        if(ToolUtil.isEmpty(param.getId())){
            return false;
        }
        AttendEmployeeMonth oldEntity = getOldEntity(param);
        if(ToolUtil.isEmpty(oldEntity)){
            return false;
        }
        //if(oldEntity.getSynchronousStatus().equals(AttendEmployeeSynchronousStatusEnum.NEW_EMPLOYEE_NOT_SUBMIT.getCode())){

        AttendEmployeeMonth newEntity = getEntity(param);
        //获取银行简称
        String bank = this.getYhCode(param.getYhk());
        //通过银行简称获取行号
        String code = btyBxdaService.getBankCode(bank);

        newEntity.setBank(bank);
        newEntity.setHh(code);

        ToolUtil.copyProperties(newEntity,oldEntity);

        boolean flag = this.updateById(newEntity);

        if((ToolUtil.isNotEmpty(newEntity.getHolidayDays())&&newEntity.getHolidayDays()<0)
                ||(ToolUtil.isNotEmpty(newEntity.getAttendanceDays())&&newEntity.getAttendanceDays()<0)
                ||(ToolUtil.isNotEmpty(newEntity.getShouldPay())&&newEntity.getShouldPay().signum() == -1)){
            if(newEntity.getHolidayDays()<0){
                newEntity.setHolidayDays(null);
            }
            if(newEntity.getAttendanceDays()<0){
                newEntity.setAttendanceDays(null);
            }
            if(newEntity.getShouldPay().signum() == -1){
                newEntity.setShouldPay(null);
            }
            int size = this.baseMapper.updateDayById(newEntity);
        }
        return flag;
    }
    /**
     * （店长考勤修改页面）编辑当员工工资为0或者空的时候允许编辑员工的工资
     *
     *
     * @author wjk
     * @Date 2021-10-18
     */
    @Override
    public boolean updateAttendEmployeeMonthForGzById(AttendEmployeeMonthParam param) {
        AttendEmployeeMonth oldEntity = getOldEntity(param);
        AttendEmployeeMonth newEntity = getEntity(param);
        boolean flag = false;
        if(ToolUtil.isEmpty(oldEntity)){
            return flag;
        }
        BigDecimal bigDecimalZero = new BigDecimal("0");
        if((oldEntity.getGz().compareTo(bigDecimalZero) == 0)
                &&(oldEntity.getGw().compareTo(bigDecimalZero) == 0)
        &&(ToolUtil.isNotEmpty(newEntity.getGz())||ToolUtil.isNotEmpty(newEntity.getGw()))){
            AttendEmployeeMonth newAttendEmployeeMonth = new AttendEmployeeMonth();
            newAttendEmployeeMonth.setId(newEntity.getId());
            newAttendEmployeeMonth.setGz(newEntity.getGz());
            newAttendEmployeeMonth.setGw(newEntity.getGw());

            AttendAuditManagerSetResult attendAuditManagerSetResultOld = new AttendAuditManagerSetResult();
            attendAuditManagerSetResultOld.setId(newAttendEmployeeMonth.getId());
            attendAuditManagerSetResultOld.setGz(newAttendEmployeeMonth.getGz());
            attendAuditManagerSetResultOld.setGw(newAttendEmployeeMonth.getGw());

            attendAuditManagerSetResultOld.setAttendanceDays(oldEntity.getAttendanceDays());
            attendAuditManagerSetResultOld.setHolidayDays(oldEntity.getHolidayDays());
            attendAuditManagerSetResultOld.setZw(oldEntity.getZw());
            attendAuditManagerSetResultOld.setAttendMonth(oldEntity.getAttendMonth());
            attendAuditManagerSetResultOld.setShouldPay(null);

            AttendAuditManagerSetResult  attendAuditManagerSetResultNew = calculateEmployeeSalary(attendAuditManagerSetResultOld, "");
            newAttendEmployeeMonth.setShouldPay(attendAuditManagerSetResultNew.getShouldPay());

            //编辑工资应发工资根据
            flag = this.updateById(newAttendEmployeeMonth);
            System.out.println("---------->"+newAttendEmployeeMonth.toString());
            if(flag){
                flag = this.baseMapper.updateByAttendEmployeeMonthId(newAttendEmployeeMonth);
                System.out.println("---------->"+newAttendEmployeeMonth.toString());
            }
        }
        return flag;
    }
    /**
     * （营运经理页面）根据营运经理的手机号码，和考核的月份返回该店的营运经理所有的店名；
     * @author wjk
     * @Date 2021-10-19
     */
    @Override
    public List<Map<String, String>> getAttendAuditShowListByYyjl(AttendAuditDdSupervisorParam param) {

        List<Map<String,String>> stringList = new ArrayList<Map<String,String>>();
        if(ToolUtil.isNotEmpty(param.getAccount())&& ToolUtil.isNotEmpty(param.getAttendMonth())){
            //若没有默认值，则默认查询已经通过的数据
            if(ToolUtil.isEmpty(param.getAuditStatus())){
                param.setAuditStatus(String.valueOf(AttendAuditStatusEnum.SUBMIT_THROUGH.getCode()));
            }
            //根据营运经理页面的手机号码，和考核的月份返回该店的营运经理页面所有的店名；
            stringList = this.baseMapper.getShopListByDdzByYyjl(param);

            if(stringList.size()>0){
                for(Map<String,String> map : stringList ){
                    if(ToolUtil.isEmpty(map.get("shouldPayAll"))){
                        map.put("shouldPayAll","0");
                    }else{
                        String shouldPayAll = String.valueOf(map.get("shouldPayAll"));
                        map.put("shouldPayAll",shouldPayAll.substring(0,shouldPayAll.indexOf(".")));
                    }
                }
            }

        }
        return stringList;
    }

    /**
     * （营运经理页面）根据营运经理的手机号码，和考核的月份返回该店的营运经理所有的店名-分页；
     * @author wjk
     * @Date 2021-11-19
     */
    @Override
    public LayuiPageInfo getAttendAuditShowListByYyjlLayuiPage(AttendAuditDdSupervisorParam param){

        LayuiPageInfo stringList = new LayuiPageInfo();
        if(ToolUtil.isNotEmpty(param.getAccount())&& ToolUtil.isNotEmpty(param.getAttendMonth())){
            //若没有默认值，则默认查询已经通过的数据
            if(ToolUtil.isEmpty(param.getAuditStatus())){
                param.setAuditStatus(String.valueOf(AttendAuditStatusEnum.SUBMIT_THROUGH.getCode()));
            }
            Page pageContext = getPageContext();
            //根据营运经理页面的手机号码，和考核的月份返回该店的运营经理页面所有的店名--分页；
            IPage page = this.baseMapper.getShopListByDdzByYyjlLayuiPage(pageContext, param);

            List<Map<String,String>> ListMap = page.getRecords();
            //System.out.println(stringList.getCount());
            if(ListMap.size()>0){
                for(Map<String,String> map : ListMap ){
                    if(ToolUtil.isEmpty(map.get("shouldPayAll"))){
                        map.put("shouldPayAll","0");
                    }else{
                        String shouldPayAll = String.valueOf(map.get("shouldPayAll"));
                        map.put("shouldPayAll",shouldPayAll.substring(0,shouldPayAll.indexOf(".")));
                    }
                }
            }
            stringList = LayuiPageFactory.createPageInfo(page);
        }
        return stringList;

    }
    /**
     * （店长考勤修改页面+员工调店） 根据店长手机号，和员工id将员工调入店长下的店
     *
     *
     * @author wjk
     * @Date 2021-09-17
     */
    @Override
    public String setEmployeeToShop(String account, AttendAuditBtyArchivesParam attendAuditBtyArchivesParam){
        if(ToolUtil.isEmpty(account)){
            return "店长手机号错误";
        }
        if(ToolUtil.isEmpty(attendAuditBtyArchivesParam.getId())){
            return "获取员工信息失败";
        }
        String resultStr = "";
        // 获取到要调店的员工信息
        AttendAuditBtyArchives attendAuditBtyArchives = this.attendAuditBtyArchivesService.getById(attendAuditBtyArchivesParam.getId());
        if(ToolUtil.isEmpty(attendAuditBtyArchives)){
            return "获取员工信息失败，未查询到该员工信息。";
        }

        //若员工根据员工手机号判断该员工在该员工为一个店的考勤店长，则不允许将员工调店
        AttendAuditBtyArea attendAuditBtyAreaArchives = this.attendAuditBtyAreaService.getShopInfoByDzPhone(attendAuditBtyArchives.getTel());
        if(ToolUtil.isNotEmpty(attendAuditBtyAreaArchives)&&ToolUtil.isNotEmpty(attendAuditBtyAreaArchives.getDm())){
            return "员工"+attendAuditBtyAreaArchives.getKqDz()+",现任["+attendAuditBtyAreaArchives.getDm()+"]考勤店长，当前不允许调店。";
        }

        //根据员工手机号判断该员工在该店长统一个运营经理下面
        List<AttendAuditBtyArchives> listYyjl = this.attendAuditBtyArchivesService.getOperationsEmployeeListByDzPhone(account,attendAuditBtyArchives.getTel());

        if(listYyjl.size()==0){
            return "获取员工信息失败,该员工和本店不属于同一个运营经理，请确认后进行调店";
        }

        AttendEmployeeMonth entity = new AttendEmployeeMonth();
        ToolUtil.copyProperties(attendAuditBtyArchives, entity);
        //将员工id存入相应的信息
        entity.setBtyArchicesId(Long.valueOf(attendAuditBtyArchives.getId()));
        //考勤月份
        //Date attendMonth =  calculateMonth(new Date(),-1);
        //entity.setAttendMonth(sdf.format(attendMonth));
        Map<String,String> map = this.attendAuditService.getAttendMonth();
        String attendMonthStr = map.get("attendMonth").replaceAll("-","");

        entity.setAttendMonth(attendMonthStr);

        entity.setSynchronousMonth(sdf.format(new Date()));

        LambdaQueryWrapper<AttendEmployeeMonth> queryWrapper = new LambdaQueryWrapper<AttendEmployeeMonth>();
        queryWrapper.eq(AttendEmployeeMonth::getBtyArchicesId,entity.getBtyArchicesId());
        queryWrapper.eq(AttendEmployeeMonth::getAttendMonth,entity.getAttendMonth());

        List<AttendEmployeeMonth> list = this.baseMapper.selectList(queryWrapper);

        //根据店长的手机号获取他旗下的店的信息
        AttendAuditBtyArea attendAuditBtyArea = this.attendAuditBtyAreaService.getShopInfoByDzPhone(account);

        //根据店长的手机号获取他的提交信息
        AttendAudit attendAudit = attendAuditService.getAttendAuditByDzPhone(account);

        //根据店长的手机号获取店长的信息
        AttendAuditBtyArchives attendAuditBtyArchivesDz = attendAuditBtyArchivesService.getOneByPhone(account);
        if(ToolUtil.isEmpty(attendAudit.getAuditStatus())){
            return "店长提交信息错误";
        }
        if(attendAudit.getAuditStatus().equals(AttendAuditStatusEnum.SUBMIT_AUDIT.getCode())){
            resultStr = "调店失败 ！已经提交审核，无法操作员工调店信息！";
        }
        if(attendAudit.getAuditStatus().equals(AttendAuditStatusEnum.SUBMIT_THROUGH.getCode())){
            resultStr = "调店失败 ！已经审核通过，无法操作员工调店信息！";
        }

        //判断是否已经做过本月的考勤信息，若没有，进行调店
        if(list.size() == 0){
            //将id对应好
            entity.setId(Long.valueOf(attendMonthStr+attendAuditBtyArchives.getId().toString()));

            //记录调店之前的店名;
            entity.setDmOld(attendAuditBtyArchives.getDm());

            //将调店之后的店名存入到该店
            entity.setDm(attendAuditBtyArea.getDm());

            //将调店员工的区域，和店长的区域对应
            entity.setQy(attendAuditBtyArchivesDz.getQy());
            entity.setEqy(attendAuditBtyArchivesDz.getEqy());

            entity.setPayWage(0);
            entity.setZtNew(0);
            //记录该员工的当月的考勤记录信息；
            entity.setAttendAuditId(attendAudit.getId());
            //记录该员工是同步过来的；
            entity.setSynchronousStatus(AttendEmployeeSynchronousStatusEnum.OLD_EMPLOYEE.getCode());

            //基本工资
            BigDecimal gz = attendAuditBtyArchives.getGz();
            //岗位工资
            BigDecimal gw = attendAuditBtyArchives.getGw();
            //gz和gw共同为空
            if(gz.equals(BigDecimal.ZERO)&& gw.equals(BigDecimal.ZERO)){
                entity.setBtyArchicesNewEmp("1");
            }else{
                entity.setBtyArchicesNewEmp("0");
            }
            int size = this.baseMapper.insert(entity);
            if(size == 1){
                resultStr = "调店成功 ！";
            }else {
                resultStr = "失败！";
            }
        }
        //判断是否已经做过本月考勤
        if(list.size() > 0){
            AttendEmployeeMonth attendEmployeeMonthOld = list.get(0);
            //查询此员工原有的考勤记录状态；
            AttendAudit attendAuditOld = attendAuditService.getById(attendEmployeeMonthOld.getAttendAuditId());
            if(String.valueOf(attendEmployeeMonthOld.getPayWage()).equals("0")){
                //已经提交，或者已经审核通过了，则不进行调店
                if(attendAuditOld.getAuditStatus().equals(AttendAuditStatusEnum.SUBMIT_AUDIT.getCode()) || attendAuditOld.getAuditStatus().equals(AttendAuditStatusEnum.SUBMIT_THROUGH.getCode())){
                    resultStr = "调店失败 ！员工已经在其他店进行了考勤，并且已经提交或者被审核通过无法进行调店！";
                }else{
                    //将调店之后的店名存入到该店
                    attendEmployeeMonthOld.setDmOld(attendEmployeeMonthOld.getDm());
                    //将调店之后的店名存入到该店
                    attendEmployeeMonthOld.setDm(attendAuditBtyArea.getDm());
                    //记录该员工的当月的考勤记录信息；
                    attendEmployeeMonthOld.setAttendAuditId(attendAudit.getId());

                    //将调店员工的区域，和店长的区域对应
                    attendEmployeeMonthOld.setQy(attendAuditBtyArchivesDz.getQy());
                    attendEmployeeMonthOld.setEqy(attendAuditBtyArchivesDz.getEqy());

                    int size = this.baseMapper.updateById(attendEmployeeMonthOld);
                    if(size > 0){
                        resultStr = "调店成功 ！已经将该员工在其他店铺的考勤信息调入到本店，请结合该员工两家店考勤信息进行填写！";
                    }else{
                        resultStr = "调店失败 ！员工已经在其他店进行了考勤，并且已经提交或者被审核通过无法进行调店！";
                    }
                }
            }else{
                //将调店之后的店名存入到该店
                attendEmployeeMonthOld.setDmOld(attendEmployeeMonthOld.getDm());
                //将调店之后的店名存入到该店
                attendEmployeeMonthOld.setDm(attendAuditBtyArea.getDm());
                //记录该员工的当月的考勤记录信息；
                attendEmployeeMonthOld.setAttendAuditId(attendAudit.getId());

                //将调店员工的区域，和店长的区域对应
                attendEmployeeMonthOld.setQy(attendAuditBtyArchivesDz.getQy());
                attendEmployeeMonthOld.setEqy(attendAuditBtyArchivesDz.getEqy());

                int size = this.baseMapper.updateById(attendEmployeeMonthOld);
                if(size > 0){
                    resultStr = "调店成功 ！已经将该员工在其他店铺的考勤信息调入到本店，请结合该员工两家店考勤信息进行填写！";
                }else{
                    resultStr = "调店失败 ！员工已经在其他店进行了考勤，并且已经提交或者被审核通过无法进行调店！";
                }
            }
        }
        return resultStr;
    }

    /**
     * （督导审核页面）根据督导或者大店长的手机号码，返回督导或者大店长所有的审核信息；
     * @author wjk
     * @Date 2021-09-18
     */
    @Override
    public List<AttendAuditManagerSetResult> getEmployeeListMonthByDdSupervisorParam(AttendAuditDdSupervisorParam param) {
        //根据督导的手机号码，返回督导所有的审核信息；
        param.setPayWage("0");
        List<AttendAuditManagerSetResult> list = this.baseMapper.getEmployeeListMonthByDdSupervisorParam(param);
        //如果督导查询到的店为0，则查这个店不发工资的人，
        if(list.size() == 0){
            //根据督导的手机号码，查询这个店不发工资的人的审核信息；
            param.setPayWage("1");
            list = this.baseMapper.getEmployeeListMonthByDdSupervisorParam(param);
        }

        //如果督导查询到的店为0，则查这个手机号是大店长的，
        if(list.size() == 0){
            //根据大店长的手机号码，返回大店长所有的审核信息；
            param.setPayWage("0");
            list = this.baseMapper.getEmployeeListMonthByDdzSupervisorParam(param);
        }
        //如果督导查询到的店为0，查询这个店不发工资的人的审核信息；
        if(list.size() == 0){
            param.setPayWage("1");
            //根据大店长的手机号码，查询这个店不发工资的人的审核信息；
            list = this.baseMapper.getEmployeeListMonthByDdzSupervisorParam(param);
        }
        List<AttendAuditManagerSetResult> listNew = setDismissedNote(list);
        return listNew;
    }

    /**
     * （督导审核页面）更新对新员工的状态(synchronous_status:(2 or 4) to 3)
     *  将店长提交状态或者督导驳回的新员工状态，更新到督导审核通过状态
     * @param param
     * @param account
     * @return
     */
    @Override
    public int newEmployeeApprove(List<AttendAuditManagerSetResult> param, String account) {
        int size= 0;
        List<Long> idlist = getIdListWithoutDuplicates(param);
        if(idlist.size()>0){
            size = this.baseMapper.newEmployeeApprove(idlist);
        }
        return size;
    }

    /**
     * （督导审核页面）更新对新员工的状态(synchronous_status: 2 to 4)
     *  将店长提交状态,更新到督导审核驳回状态
     * @param param
     * @param account
     * @return
     */
    @Override
    public int newEmployeeBack(List<AttendAuditManagerSetResult> param, String account) {
        int size= 0;
        List<Long> idlist = getIdListWithoutDuplicates(param);
        if(idlist.size()>0){
            size = this.baseMapper.newEmployeeBack(idlist);
        }
        return size;
    }

    /**
     * （督导审核页面）根据督导选择店，月份，返回计算的（待审核，加上已审核通过的人员的应发工资总数）；
     * @author wjk
     * @Date 2021-09-18
     */
    @Override
    public Map<String, String> getShouldPayByDdSupervisor(AttendAuditDdSupervisorParam param) {


        //参数中attendMonth 不能为空！！
        param = attendMonthIsNotNull(param);

        Map<String, String> map = new HashMap<String, String>();
        //此处将默认值补全防止前端出现找不到数据情况，也根据默认值验证是否走大店长
        //手机号，考勤月份，提交月份，店铺名称，应发工资，店铺总数
        map.put("account",param.getAccount());
        map.put("attendMonth",param.getAttendMonth());
        map.put("submitMonth",param.getSubmitMonth());
        map.put("shopName",param.getShopName());
        map.put("shouldPayAll","0");
        map.put("shopCount", "0");
        map.put("notSubmitShopCount", "0");
        map.put("submitAuditShopCount", "0");
        map.put("submitThroughShopCount", "0");
        map.put("submitBackShopCount", "0");
        map.put("shouldPayEmployeeNum", "0");
        //此处确定手机号，若手机号为空，则不必要进行之后的查询
        if (ToolUtil.isEmpty(param.getAccount())) {
            return map;
        }
        //根据用户的id 获取用户的信息，获取用户的名称；
        AttendAuditBtyArchives attendAuditBtyArchivesdd = attendAuditBtyArchivesService.getOneByPhone(param.getAccount());
        //如果获取的用户的id为空，则证明此用户没有，返回空
        if(ToolUtil.isEmpty(attendAuditBtyArchivesdd.getId())){
            return map;
        }
        String userName = attendAuditBtyArchivesdd.getXm();

        //如果是督导，督导的姓名去查询相应的店铺，获取督导的列表
        List<AttendAuditBtyArea> list = attendAuditBtyAreaService.getShowListByDdName(userName,"");
        //若督导列表查询不到数据则查询大店长下的店铺，返回相应的数据
        if(list.size()>0){
            //此处获取督导的数据
            map = getShouldPayByDdSupervisorForDd(param,map,list);
        }else{
            list = attendAuditBtyAreaService.getShowListByDdzName(userName,"");
            if(list.size()> 0){
                //此处获取大店长的数据
                map = getShouldPayByDdSupervisorForDdz(param,map,list);
            }else{
                return map;
            }
        }
        return map;
    }

    /**
     * 此处获取大店长的数据
     * @param param
     * @param map
     * @param AttendAuditBtyAreaList
     * @return
     */
    public Map<String, String> getShouldPayByDdSupervisorForDdz(AttendAuditDdSupervisorParam param,Map<String, String> map,List<AttendAuditBtyArea> AttendAuditBtyAreaList){


        //***此处获取基础的一些数据：应发工资，手机号，考勤月份，提交月份，店铺名称*********************************************************************************************
        List<Map<String, String>> list = this.baseMapper.getShouldPayByDdzSupervisor(param);
        if(list.size()>0){
            map = list.get(0);
            if(ToolUtil.isNotEmpty(map.get("shouldPayAll"))){
                int shouldPayAll =Double.valueOf(String.valueOf(map.get("shouldPayAll"))).intValue();
                map.put("shouldPayAll",String.valueOf(shouldPayAll));
            }else{
                map.put("shouldPayAll","0");
            }
        }else{
            map.put("shouldPayAll","0");
        }

        map.put("account",param.getAccount());
        map.put("attendMonth",param.getAttendMonth());
        map.put("submitMonth",param.getSubmitMonth());
        map.put("shopName",param.getShopName());

        //***此处获取基础的一些数据：应发工资的总店数*********************************************************************************************
        //List<AttendAuditBtyArea> AttendAuditBtyAreaList = this.attendAuditBtyArchivesService.getShopListByDdPhone(param.getAccount(),null);
        map.put("shopCount", String.valueOf(AttendAuditBtyAreaList.size()));

        //根据督导的手机号，和提交月份或者考勤月份，获得该月的考勤数据
        Map<String,String> statusMap = this.attendAuditService.getStatusCountByDdz(param);

        //***此处获取基础的一些数据：未提交的店铺数量，待审核店铺数量，审核通过店铺数量，审核驳回店铺数量 *********************************************************************************************
        int submitAudit = 0;
        int submitThrough = 0;
        int submitBack = 0;
        if(ToolUtil.isNotEmpty(statusMap)){
            if(ToolUtil.isNotEmpty(statusMap.get("SUBMIT_AUDIT"))){
                submitAudit = Integer.parseInt(String.valueOf(statusMap.get("SUBMIT_AUDIT")));
            }
            if(ToolUtil.isNotEmpty(statusMap.get("SUBMIT_THROUGH"))){
                submitThrough = Integer.parseInt(String.valueOf(statusMap.get("SUBMIT_THROUGH")));
            }
            if(ToolUtil.isNotEmpty(statusMap.get("SUBMIT_BACK"))){
                submitBack = Integer.parseInt(String.valueOf(statusMap.get("SUBMIT_BACK")));
            }
        }

        int notSubmit = AttendAuditBtyAreaList.size() - submitAudit - submitThrough -submitBack ;

        map.put("notSubmitShopCount", String.valueOf(notSubmit));
        map.put("submitAuditShopCount", String.valueOf(submitAudit));
        map.put("submitThroughShopCount", String.valueOf(submitThrough));
        map.put("submitBackShopCount", String.valueOf(submitBack));
        //根据督导的手机号，和提交月份或者考勤月份，还有店铺名称，获取该店的考勤信息数据
        //***此处获取基础的一些数据：获取单店的应发工资人数 *********************************************************************************************
        Map<String,String> shouldPayPersonSumMap  = this.baseMapper.getShouldPayPersonSumByDdzSupervisor(param);
        //总应发工资人数
        int shouldPayPersonSum = 0;
        if(ToolUtil.isNotEmpty(shouldPayPersonSumMap)){
            if(ToolUtil.isNotEmpty(shouldPayPersonSumMap.get("EMPLOYEENUM"))){
                shouldPayPersonSum = Integer.parseInt(String.valueOf(shouldPayPersonSumMap.get("EMPLOYEENUM")));
            }
        }
        map.put("shouldPayEmployeeNum", String.valueOf(shouldPayPersonSum) );

        return map;
    }


    /**
     * 此处获取督导的数据
     * @param param
     * @param map
     * @param AttendAuditBtyAreaList
     * @return
     */
    public Map<String, String> getShouldPayByDdSupervisorForDd(AttendAuditDdSupervisorParam param,Map<String, String> map,List<AttendAuditBtyArea> AttendAuditBtyAreaList){
        //***此处获取基础的一些数据：应发工资，手机号，考勤月份，提交月份，店铺名称*********************************************************************************************
        List<Map<String, String>> list = this.baseMapper.getShouldPayByDdSupervisor(param);
        if(list.size()>0){
            map = list.get(0);
            if(ToolUtil.isNotEmpty(map.get("shouldPayAll"))){
                int shouldPayAll =Double.valueOf(String.valueOf(map.get("shouldPayAll"))).intValue();
                map.put("shouldPayAll",String.valueOf(shouldPayAll));
            }else{
                map.put("shouldPayAll","0");
            }
        }else{
            map.put("shouldPayAll","0");
        }

        map.put("account",param.getAccount());
        map.put("attendMonth",param.getAttendMonth());
        map.put("submitMonth",param.getSubmitMonth());
        map.put("shopName",param.getShopName());

        //***此处获取基础的一些数据：应发工资的总店数*********************************************************************************************
        //List<AttendAuditBtyArea> AttendAuditBtyAreaList = this.attendAuditBtyArchivesService.getShopListByDdPhone(param.getAccount(),null);
        map.put("shopCount", String.valueOf(AttendAuditBtyAreaList.size()));
        //根据督导的手机号，和提交月份或者考勤月份，获得该月的考勤数据
        Map<String,String> statusMap = this.attendAuditService.getStatusCountByDd(param);

        //***此处获取基础的一些数据：未提交的店铺数量，待审核店铺数量，审核通过店铺数量，审核驳回店铺数量 *********************************************************************************************
        int submitAudit = 0;
        int submitThrough = 0;
        int submitBack = 0;
        if(ToolUtil.isNotEmpty(statusMap)){
            if(ToolUtil.isNotEmpty(statusMap.get("SUBMIT_AUDIT"))){
                submitAudit = Integer.parseInt(String.valueOf(statusMap.get("SUBMIT_AUDIT")));
            }
            if(ToolUtil.isNotEmpty(statusMap.get("SUBMIT_THROUGH"))){
                submitThrough = Integer.parseInt(String.valueOf(statusMap.get("SUBMIT_THROUGH")));
            }
            if(ToolUtil.isNotEmpty(statusMap.get("SUBMIT_BACK"))){
                submitBack = Integer.parseInt(String.valueOf(statusMap.get("SUBMIT_BACK")));
            }
        }

        int notSubmit = AttendAuditBtyAreaList.size() - submitAudit - submitThrough -submitBack ;

        map.put("notSubmitShopCount", String.valueOf(notSubmit));
        map.put("submitAuditShopCount", String.valueOf(submitAudit));
        map.put("submitThroughShopCount", String.valueOf(submitThrough));
        map.put("submitBackShopCount", String.valueOf(submitBack));

        //根据督导的手机号，和提交月份或者考勤月份，还有店铺名称，获取该店的考勤信息数据
        //***此处获取基础的一些数据：获取单店的应发工资人数 *********************************************************************************************
        Map<String,String> shouldPayPersonSumMap  = this.baseMapper.getShouldPayPersonSumByDdSupervisor(param);
        //总应发工资人数
        int shouldPayPersonSum = 0;
        if(ToolUtil.isNotEmpty(shouldPayPersonSumMap)){
            if(ToolUtil.isNotEmpty(shouldPayPersonSumMap.get("EMPLOYEENUM"))){
                shouldPayPersonSum = Integer.parseInt(String.valueOf(shouldPayPersonSumMap.get("EMPLOYEENUM")));
            }
        }
        map.put("shouldPayEmployeeNum", String.valueOf(shouldPayPersonSum) );

        return map;
    }
    /**
     * 督导页面考勤月份不能为空
     * 考勤月份信息不能为空，为空默认上个月，若是本月最后几天配置内，则默认本月
     * @author wjk
     * @Date 2021-09-18
     */
    public AttendAuditDdSupervisorParam attendMonthIsNotNull(AttendAuditDdSupervisorParam param){
        if(param.getAttendMonth() == null || param.getAttendMonth().equals("") ||param.getAttendMonth().length()!=6) {
            //param.setSubmitMonth(sdf.format(new Date()));//默认的同步月份必须为空的
            //param.setAttendMonth(sdf.format(calculateMonth(new Date(), -1)));
            Map<String,String> map = attendAuditBtyArchivesService.intoAttendEmployeeMonthListValidationParam(null,null);
            String attendMonth = map.get("attendMonth").replaceAll("-","");
            param.setAttendMonth(attendMonth);

        }
        return param;
    }
    /**
     * 店长页面考勤月份不能为空
     * 考勤月份信息不能为空，为空默认上个月，若是本月最后几天配置内，则默认本月
     * @author wjk
     * @Date 2021-09-18
     */
    public AttendAuditManagerSetParam attendMonthIsNotNullForDz(AttendAuditManagerSetParam param){
        if(param.getAttendMonth() == null || param.getAttendMonth().equals("") ||param.getAttendMonth().length()!=6) {
            //param.setSubmitMonth(sdf.format(new Date()));//默认的同步月份必须为空的
            //param.setAttendMonth(sdf.format(calculateMonth(new Date(), -1)));
            Map<String,String> map = attendAuditBtyArchivesService.intoAttendEmployeeMonthListValidationParam(null,null);
            String attendMonth = map.get("attendMonth").replaceAll("-","");
            param.setAttendMonth(attendMonth);

        }
        return param;
    }
//    /**
//     *
//     * @author wjk
//     * @Date 2021-09-18
//     */
//    public AttendAuditDdSupervisorParam submitMonthIsNotNull(AttendAuditDdSupervisorParam param){
//
//        if(param.getSubmitMonth() ==  null || param.getSubmitMonth().equals("")){
//            if(param.getAttendMonth() == null || param.getAttendMonth().equals("")){
//                param.setSubmitMonth(sdf.format(new Date()));
//            }else if(param.getAttendMonth().length()!=6){
//                param.setSubmitMonth(sdf.format(new Date()));
//                param.setAttendMonth(null);
//            }else{
//                try {
//                    String attendTime = param.getAttendMonth()+"01 01:00:00";
//                    Date date = sdfh.parse(attendTime);
//                    Calendar rightNow = Calendar.getInstance();
//                    rightNow.setTime(date);
//                    rightNow.add(Calendar.MONTH, 1);
//                    Date dt1 = rightNow.getTime();
//                    param.setSubmitMonth(sdf.format(dt1));
//                }catch (Exception e){
//                    e.printStackTrace();
//                }
//            }
//        }
//
//        return param;
//
//    }
    /**
     * （店长考勤修改页面+新增员工信息）删除员工信息，根据店长的电话 和 员工的id
     *
     *
     * @author wjk
     * @Date 2021-09-18
     */
    @Override
    public boolean deleteAttendEmployeeMonth(String account, String id) {
        boolean flag = false;
        if(ToolUtil.isEmpty(id)){
            return flag;
        }
        AttendEmployeeMonthParam param = new AttendEmployeeMonthParam();
        param.setId(Long.valueOf(id));
        AttendEmployeeMonth oldEntity = getOldEntity(param);
        if(ToolUtil.isEmpty(oldEntity)){
            return flag;
        }
        //只允许删除新增加员工，并且状态是未提交状态的员工
        if(ToolUtil.isNotEmpty(oldEntity)){
            if(oldEntity.getSynchronousStatus().equals(AttendEmployeeSynchronousStatusEnum.NEW_EMPLOYEE_NOT_SUBMIT.getCode())){
                flag = this.removeById(getKey(param));
            }
        }
        return flag;
    }

    /**
     * （店长考勤页面）根据店名，月份，返回计算的（待审核，加上已审核通过的人员的应发工资总数，和人员总数）；
     * @author wjk
     * @Date 2021-09-22
     */
    @Override
    public Map<String, String> getShouldPayByDzInfo(AttendAuditDdSupervisorParam param) {

        Map<String, String> map = new HashMap<String, String>();

        //参数中attendMonth 不能为空！！
        param = attendMonthIsNotNull(param);

        List<Map<String, String>> list = this.baseMapper.getShouldPayByDzInfo(param);

        if(list.size()>0){
            map = list.get(0);
            if(ToolUtil.isNotEmpty(map.get("shouldPayAll"))){
                int shouldPayAll =Double.valueOf(String.valueOf(map.get("shouldPayAll"))).intValue();
                map.put("shouldPayAll",String.valueOf(shouldPayAll));
            }else{
                map.put("shouldPayAll","0");;
            }
            //计算所有的本月的员工数
            Map<String, String> employeeNumMap = this.baseMapper.getEmployeeNumByDzInfo(param);
            if(ToolUtil.isNotEmpty(employeeNumMap)){
                if(ToolUtil.isNotEmpty(employeeNumMap.get("employeeNum"))){
                    int employeeNum =Integer.parseInt(String.valueOf(employeeNumMap.get("employeeNum")));
                    map.put("employeeNum",String.valueOf(employeeNum));
                }
            }

        }else{
            map.put("shouldPayAll","0");
            map.put("employeeNum","0");
            map.put("shouldPayEmployeeNum","0");
            map.put("account",param.getAccount());
            map.put("attendMonth",param.getAttendMonth());
            map.put("submitMonth",param.getSubmitMonth());
        }

        if(StringUtils.isEmpty(param.getShopName())){
            //根据店长的手机号获取店名信息
            AttendAuditBtyArea attendAuditBtyArea = attendAuditBtyAreaService.getShopInfoByDzPhone(param.getAccount());
            String shopName = attendAuditBtyArea.getDm();
            map.put("shopName",shopName);
        }else{
            map.put("shopName",param.getShopName());
        }
        return map;
    }

    /**
     * 根据列表查询这些员工已经做过本月考勤记录列表
     * @author wjk
     * @Date 2021-09-23
     */
    @Override
    public List<AttendEmployeeMonth> getEmployeeListByAuditBtyArchiveList(List<AttendEmployeeMonth> attendEmployeeMonthList,String attendMonth) {
        if(attendEmployeeMonthList.size()>0){
            return this.baseMapper.getEmployeeListByAuditBtyArchiveList(attendEmployeeMonthList,attendMonth);
        }else{
            return attendEmployeeMonthList;
        }
    }
    /**
     * （店长考勤页面）根据员工信息，计算员工考勤的月份的信息
     * 应发工资=（（岗位工资+基本工资）/本月总天数）*（出勤天数+公休）
     * @author wjk
     * @Date 2021-09-28
     */
    @Override
    public AttendAuditManagerSetResult calculateEmployeeSalary(AttendAuditManagerSetResult attendAuditManagerSetResult, String account) {
        if(ToolUtil.isEmpty(attendAuditManagerSetResult.getId())){
            return attendAuditManagerSetResult;
        }

        //基本工资
        BigDecimal gz = attendAuditManagerSetResult.getGz();
        //岗位工资
        BigDecimal gw = attendAuditManagerSetResult.getGw();
        //出勤天数
        Float attendanceDays = attendAuditManagerSetResult.getAttendanceDays();
        //公休天数
        Float holidayDays = attendAuditManagerSetResult.getHolidayDays();
        //本月应发工资
        BigDecimal shouldPay = attendAuditManagerSetResult.getShouldPay();
        //若职位为空
        if(ToolUtil.isEmpty(attendAuditManagerSetResult.getZw())){
            return attendAuditManagerSetResult;
        }
        //POSITION6(6,"钟点工")，小时乘以工资数       //POSITION7(7,"兼职")，天数乘以工资数   //POSITION8(8,"小时工")，天数乘以工资数
        if(attendAuditManagerSetResult.getZw().equals(EmployeePositionEnum.POSITION6.getMsg())||attendAuditManagerSetResult.getZw().equals(EmployeePositionEnum.POSITION7.getMsg())||attendAuditManagerSetResult.getZw().equals(EmployeePositionEnum.POSITION8.getMsg())){
            if (ToolUtil.isNotEmpty(gz)&&ToolUtil.isNotEmpty(attendanceDays)) {
                //计算月度应发工资天数
                BigDecimal days = new BigDecimal(String.valueOf(attendanceDays));
                //计算月度应发薪薪资四舍五入值
                shouldPay =  gz.multiply(days);
            }
            attendAuditManagerSetResult.setShouldPay(shouldPay);
        }else{

            String attendMonthDay = attendAuditManagerSetResult.getAttendMonth()+"01 00:00:00";
            Date date = new Date();
            try {
                 date = sdfh.parse(attendMonthDay);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            //获取考勤月的日期
            Date beforeOneMonthDate =  calculateMonth(date,0);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(beforeOneMonthDate);
            int MaxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

            //四个数值不能为空
            if (ToolUtil.isNotEmpty(gz)&&ToolUtil.isNotEmpty(gw)&&ToolUtil.isNotEmpty(attendanceDays)&&ToolUtil.isNotEmpty(holidayDays)) {
                //计算月度工资加岗位薪资
                BigDecimal gzgw = gz.add(gw);
                //计算月度应发工资天数
                BigDecimal days = new BigDecimal(String.valueOf(attendanceDays+holidayDays));
                //计算月度总天数
                BigDecimal maxDay = new BigDecimal(String.valueOf(MaxDay));
                //计算月度1人天薪资数
                BigDecimal gzgwday = gzgw.divide(maxDay,20,BigDecimal.ROUND_HALF_UP);
                //计算月度应发薪资数
                BigDecimal shouldPayBigDecimal = gzgwday.multiply(days);
                //计算月度应发薪薪资四舍五入值
                shouldPay = shouldPayBigDecimal.setScale(0, BigDecimal.ROUND_HALF_UP);
            }
            attendAuditManagerSetResult.setShouldPay(shouldPay);
        }
        return attendAuditManagerSetResult;

    }

    /**
     * 根据返回的员工列表其中的新员工的id；
     * @author wjk
     * @Date 2021-09-18
     */
    private List<Long> getIdListWithoutDuplicates(List<AttendAuditManagerSetResult> param){
        ArrayList<Long> idList = new ArrayList<Long>();
        param.forEach(attendAuditManagerSetResult ->{
            if(attendAuditManagerSetResult.getSynchronousStatus().equals(AttendEmployeeSynchronousStatusEnum.NEW_EMPLOYEE_SUBMIT.getCode())){
                idList.add(attendAuditManagerSetResult.getId());
            }
        });
        //System.out.println(aaIdList);
        List<Long> idListWithoutDuplicates = idList.stream().distinct().collect(Collectors.toList());
        //System.out.println(aaIdListWithoutDuplicates);
        return idListWithoutDuplicates;
    }

    /**
     * 对一个列表按照splitNum进行分割。
     *
     * @param lists
     * @param splitNum
     * @param <T>
     * @return
     */
    public static <T>List<AttendEmployeeMonth>[] splitLists(List<AttendEmployeeMonth> lists, int splitNum) {
        int listSize;
        if (lists == null || (listSize = lists.size()) < 1) {
            return new ArrayList[0];
        }
        int length = listSize % splitNum == 0 ? listSize / splitNum : listSize / splitNum + 1;
        // 这里面如果用ArrayList，会在50行报错。ArrayList list = new List();这样会报错。
        List<AttendEmployeeMonth>[] results = new List[length];
        int fromIndex, toIndex;
        for (int i = 0; i < length; i++) {
            fromIndex = i * splitNum;
            toIndex = (fromIndex + splitNum) > listSize ? listSize : (fromIndex + splitNum);
            results[i] = lists.subList(fromIndex, toIndex);
        }
        return results;
    }

    /**
     *  通过银行卡号获取银行简称
     * @param yhk
     * @return
     */
    public String getYhCode(String yhk){
        RestTemplate restTemplate = new RestTemplate();
        String url = "https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo="+yhk+"&cardBinCheck=true";
        String content = restTemplate.getForObject(url, String.class);
        JSONObject jsonObject = JSONObject.parseObject(content);
        String bank="";
        if(ToolUtil.isNotEmpty(jsonObject.get("bank"))){
            bank = jsonObject.get("bank").toString();
        }
        return bank;
    }

    /**
     * 传入具体日期 ，返回具体日期增加或者减少天数，传出日期
     * @author wjk
     * @Date 2021-09-27
     */
    private  Date calculateDay(Date date,int day){
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(date);
        rightNow.add(Calendar.DATE, day);
        Date date1  = rightNow.getTime();
        return date1;
    }


    /**
     * 传入具体日期 ，返回具体日期增加或者减少月数，传出日期
     * @author wjk
     * @Date 2021-09-27
     */
    @Override
    public Date calculateMonth(Date date,int month){
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(date);
        rightNow.add(Calendar.MONTH, month);
        Date date1  = rightNow.getTime();
        return date1;
    }
    /**
     * （督导审核页面）根据督导的手机号码，和考核的月份返回该店的督导所有的店名；
     * @author wjk
     * @Date 2021-10-08
     */
    @Override
    public String[] getAttendAuditShowListByDdSupervisor(AttendAuditDdSupervisorParam param) {
        if(ToolUtil.isNotEmpty(param.getAccount())&& ToolUtil.isNotEmpty(param.getAttendMonth())&& ToolUtil.isNotEmpty(param.getAuditStatus())){
            String[] stringArray = this.baseMapper.getShopListByDdSupervisor(param);
            return stringArray;
        }else{
            return new String[]{};
        }

    }

    /**
     * （督导审核页面）根据督导的手机号码，和考核的月份返回该店的督导所有的店名；
     * @author wjk
     * @Date 2021-10-14
     */
    @Override
    public List<Map<String,String>> getAttendAuditShowListByDdSupervisorList(AttendAuditDdSupervisorParam param) {
        List<Map<String,String>> stringList = new ArrayList<Map<String,String>>();
        if(ToolUtil.isNotEmpty(param.getAccount())&& ToolUtil.isNotEmpty(param.getAttendMonth())&& ToolUtil.isNotEmpty(param.getAuditStatus())){
            //根据督导的手机号码，和考核的月份返回该店的督导所有的店名；
            stringList = this.baseMapper.getShopListByDdSupervisorList(param);
            //如果，督导查不到数据，则查询大店长的数据
            if(stringList.size() == 0){
                //根据大店长的手机号码，和考核的月份返回该店的大店长所有的店名；
                stringList = this.baseMapper.getShopListByDdzSupervisorList(param);

            }
            if(stringList.size()>0){
                for(Map<String,String> map : stringList ){
                    if(ToolUtil.isEmpty(map.get("shouldPayAll"))){
                        map.put("shouldPayAll","0");
                    }else{
                        String shouldPayAll = String.valueOf(map.get("shouldPayAll"));
                        map.put("shouldPayAll",shouldPayAll.substring(0,shouldPayAll.indexOf(".")));
                    }
                }
            }

        }
        return stringList;
    }
    /**
     * 修改若有新员工，则更改新员工状态,为提交状态
     *
     * @param aaId
     * @Date 2021-10-09
     */
    @Override
    public int newEmployeeSubmitAudit(String aaId) {
        return this.baseMapper.newEmployeeSubmitAudit(aaId);
    }

    /**
     * （店长考勤修改页面）根据店长的手机号码，返回店长是应该跳转考勤页还是应该创建考勤页（若未创建考勤，状态为0，若已经创建了考勤，则状态为1）；
     * @param account
     * @param attendMonth
     * @return
     */
    @Override
    public Map<String, String> getPageByDzPhone(String account, String attendMonth) {
        Map<String,String> map = attendAuditBtyArchivesService.intoAttendEmployeeMonthListValidationParam(account,attendMonth);
        account = map.get("account");
        attendMonth = map.get("attendMonth");
        List<AttendEmployeeMonth> attendEmployeeMonth =  getEmployeeListMonthByDzPhone(account,attendMonth);
        Map<String,String> mapResult = new HashMap<String,String>();
        if(attendEmployeeMonth.size()>0){
            mapResult.put("status","1");
        }else{
            mapResult.put("status","0");
        }
        return mapResult;
    }
    /**
     * （运营经理页面）根据督导选择店，月份，返回计算的（已审核通过的人员的应发工资总数）；
     * @author wjk
     * @Date 2021-09-18
     */
    @Override
    public Map<String, String> getShouldPayByYyjl(AttendAuditDdSupervisorParam param) {

        //参数中attendMonth 不能为空！！
        param = attendMonthIsNotNull(param);

        Map<String, String> map = new HashMap<String, String>();
        //此处将默认值补全防止前端出现找不到数据情况，也根据默认值验证是否走大店长
        //手机号，考勤月份，提交月份，店铺名称，应发工资，店铺总数
        map.put("account",param.getAccount());
        map.put("attendMonth",param.getAttendMonth());
        map.put("submitMonth",param.getSubmitMonth());
        map.put("shopName",param.getShopName());
        map.put("shouldPayAll","0");
        map.put("shopCount", "0");
        map.put("notSubmitShopCount", "0");
        map.put("submitAuditShopCount", "0");
        map.put("submitThroughShopCount", "0");
        map.put("submitBackShopCount", "0");
        map.put("shouldPayEmployeeNum", "0");
        //此处确定手机号，若手机号为空，则不必要进行之后的查询
        if (ToolUtil.isEmpty(param.getAccount())) {
            return map;
        }
        //根据用户的id 获取用户的信息，获取用户的名称；
        AttendAuditBtyArchives attendAuditBtyArchivesdd = attendAuditBtyArchivesService.getOneByPhone(param.getAccount());
        //如果获取的用户的id为空，则证明此用户没有，返回空
        if(ToolUtil.isEmpty(attendAuditBtyArchivesdd.getId())){
            return map;
        }
        String userName = attendAuditBtyArchivesdd.getXm();

        //运营经理的姓名去查询相应的店铺，获取督导的列表
        List<AttendAuditBtyArea> list = attendAuditBtyAreaService.getShowListByYyjlName(userName,"");
        if(list.size()>0){
            //此处获取运营经理的数据
            map = getShouldPayByDdSupervisorForYyjl(param,map,list);
        }
        return map;
    }
    /**
     * （运营经理审核页面）根据运营经理的手机号码，返回该店的督导所有的审核信息；
     * @author wjk
     * @Date 2021-09-19
     */
    @Override
    public List<AttendAuditManagerSetResult> getEmployeeListMonthByYyjlSupervisorParam(AttendAuditDdSupervisorParam param) {
        //根据运营经理的手机号码，返回运营经理所有的审核信息；
        List<AttendAuditManagerSetResult> list = this.baseMapper.getEmployeeListMonthByYyjlSupervisorParam(param);
        return list;
    }

    /**
     * （运营经理审核页面）根据运营经理的手机号码，返回该店的督导所有的审核信息-分页；
     * @author wjk
     * @Date 2021-11-19
     */
    @Override
    public LayuiPageInfo getEmployeeListMonthByYyjlSupervisorParamLayuiPage(AttendAuditDdSupervisorParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.getEmployeeListMonthByYyjlSupervisorParamLayuiPage(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }


    /**
     * 此处获取督导的数据
     * @param param
     * @param map
     * @param AttendAuditBtyAreaList
     * @return
     */
    public Map<String, String> getShouldPayByDdSupervisorForYyjl(AttendAuditDdSupervisorParam param,Map<String, String> map,List<AttendAuditBtyArea> AttendAuditBtyAreaList){

        //***此处获取基础的一些数据：应发工资，手机号，考勤月份，提交月份，店铺名称***
        List<Map<String, String>> list = this.baseMapper.getShouldPayByYyjlSupervisor(param);
        if(list.size()>0){
            map = list.get(0);
            if(ToolUtil.isNotEmpty(map.get("shouldPayAll"))){
                int shouldPayAll =Double.valueOf(String.valueOf(map.get("shouldPayAll"))).intValue();
                map.put("shouldPayAll",String.valueOf(shouldPayAll));
            }else{
                map.put("shouldPayAll","0");
            }
        }else{
            map.put("shouldPayAll","0");
        }

        map.put("account",param.getAccount());
        map.put("attendMonth",param.getAttendMonth());
        map.put("submitMonth",param.getSubmitMonth());
        map.put("shopName",param.getShopName());

        //***此处获取基础的一些数据：应发工资的总店数***
        //List<AttendAuditBtyArea> AttendAuditBtyAreaList = this.attendAuditBtyArchivesService.getShopListByDdPhone(param.getAccount(),null);
        map.put("shopCount", String.valueOf(AttendAuditBtyAreaList.size()));
        //根据督导的手机号，和提交月份或者考勤月份，获得该月的考勤数据
        Map<String,String> statusMap = this.attendAuditService.getStatusCountByYyjl(param);

        //***此处获取基础的一些数据：未提交的店铺数量，待审核店铺数量，审核通过店铺数量，审核驳回店铺数量 ***
        int submitAudit = 0;
        int submitThrough = 0;
        int submitBack = 0;
        if(ToolUtil.isNotEmpty(statusMap)){
            if(ToolUtil.isNotEmpty(statusMap.get("SUBMIT_AUDIT"))){
                submitAudit = Integer.parseInt(String.valueOf(statusMap.get("SUBMIT_AUDIT")));
            }
            if(ToolUtil.isNotEmpty(statusMap.get("SUBMIT_THROUGH"))){
                submitThrough = Integer.parseInt(String.valueOf(statusMap.get("SUBMIT_THROUGH")));
            }
            if(ToolUtil.isNotEmpty(statusMap.get("SUBMIT_BACK"))){
                submitBack = Integer.parseInt(String.valueOf(statusMap.get("SUBMIT_BACK")));
            }
        }

        int notSubmit = AttendAuditBtyAreaList.size() - submitAudit - submitThrough -submitBack ;

        map.put("notSubmitShopCount", String.valueOf(notSubmit));
        map.put("submitAuditShopCount", String.valueOf(submitAudit));
        map.put("submitThroughShopCount", String.valueOf(submitThrough));
        map.put("submitBackShopCount", String.valueOf(submitBack));

        //根据运营经理的手机号，和提交月份或者考勤月份，还有店铺名称，获取该店的考勤信息数据
        //***此处获取基础的一些数据：获取单店的应发工资人数 *********************************************************************************************
        Map<String,String> shouldPayPersonSumMap  = this.baseMapper.getShouldPayPersonSumByYyjlSupervisor(param);
        //总应发工资人数
        int shouldPayPersonSum = 0;
        if(ToolUtil.isNotEmpty(shouldPayPersonSumMap)){
            if(ToolUtil.isNotEmpty(shouldPayPersonSumMap.get("EMPLOYEENUM"))){
                shouldPayPersonSum = Integer.parseInt(String.valueOf(shouldPayPersonSumMap.get("EMPLOYEENUM")));
            }
        }
        map.put("shouldPayEmployeeNum", String.valueOf(shouldPayPersonSum) );

        return map;
    }

//    /**
//     * （店长考勤修改页面+重建考勤信息） 根据店长手机号，考勤的月份，重建店长当月的建考勤信息
//     *
//     *
//     * @author wjk
//     * @Date 2021-10-28
//     */
//    @Override
//    public  int setEmployeeListByDzPhoneRestart(AttendAuditDdSupervisorParam param){
//        //参数中attendMonth 不能为空！！
//        param = attendMonthIsNotNull(param);
//        //若电话为空，则返回吧
//        if(ToolUtil.isEmpty(param.getAccount())){
//            return 0;
//        }
//        //根据店长手机号，和考勤数据，删除这家店这个月的员工考勤信息，
//        int deleteAttendEmployeeMothSize = this.baseMapper.deleteAttendEmployeeMothByAccount(param);
//        //删除驳回记录，
//        int deleteAttendDismissesdSize = this.attendDismissedService.deleteAttendDismissedByAccount(param);
//        //根据店长手机号，和考勤时间，删除这家店这个月的员工信息提交信息
//        int deleteAttendAuditSize =  this.attendAuditService.deleteAttendAuditByAccount(param);
//
//
//        //创建考勤信息
//        int size = this.attendAuditBtyArchivesService.intoAttendEmployeeMonthListByDzPhone(param.getAccount(),param.getAttendMonth());
//        return size;
//    }


    /**
     * （店长考勤修改页面+重建考勤信息） 根据店长手机号，考勤的月份，重建店长当月的建考勤信息
     *
     *
     * @author wjk
     * @Date 2021-10-28
     */
    @Override
    public  int setEmployeeListByDzPhoneRestart(AttendAuditDdSupervisorParam param){
        //参数中attendMonth 不能为空！！
        param = attendMonthIsNotNull(param);
        //若电话为空，则返回吧
        if(ToolUtil.isEmpty(param.getAccount())){
            return 0;
        }
        //若提交的状态没有并且提交为空的，则判断不允许进行造作
        AttendAudit attendAudit =  this.attendAuditService.getAttendAuditByDzPhone(param.getAccount());
        if(ToolUtil.isEmpty(attendAudit)||ToolUtil.isEmpty(attendAudit.getAuditStatus())){
            return 0;
        }
        //若已经提交审核，或则已经提交审核了，则不进行同步
        if(String.valueOf(attendAudit.getAuditStatus()).equals(String.valueOf(AttendAuditStatusEnum.SUBMIT_AUDIT.getCode()))
                ||String.valueOf(attendAudit.getAuditStatus()).equals(String.valueOf(AttendAuditStatusEnum.SUBMIT_THROUGH.getCode()))){
            return 0;
        }

        int sizeBtyArchivesOld = 0;
        int sizeBtyArchivesNew = 0;
        //查询到这个店，所有本店员工，未进行过调店到其他店的员工和调店到本店的员工信息！
        List<AttendEmployeeMonth> AttendEmployeeMonthList = this.baseMapper.getEmployeeListMonthOnlyInShopByDzAccount(param);


        if(ToolUtil.isNotEmpty(AttendEmployeeMonthList)&&AttendEmployeeMonthList.size()>0){
            // 获取到这些员工中，gw和gz 为零的情况,
            List<AttendAuditBtyArchives> attendAuditBtyArchivesListBtyArchives = this.baseMapper.getBtyArchivesListNewEmployee(AttendEmployeeMonthList,param.getAttendMonth());
            //将这些员工中gw和gz中为零的情况不进行排除数据，则进行排除员工信息同步
            if(ToolUtil.isNotEmpty(attendAuditBtyArchivesListBtyArchives)&&attendAuditBtyArchivesListBtyArchives.size()>0){
                List<AttendEmployeeMonth>  AttendEmployeeMonthListNew = dealWith(AttendEmployeeMonthList,attendAuditBtyArchivesListBtyArchives);
                if(AttendEmployeeMonthListNew.size()>0){
                    //更新到这个店，所有本店员工，未进行过调店到其他店的员工和调店到本店的员工信息！,除去店长那边的信息
                    sizeBtyArchivesOld = this.baseMapper.updateAttendEmployeeMothOnlyInShopByDzAccount(AttendEmployeeMonthListNew,param.getAttendMonth());
                }
                //更新到这个店，所有人资表中新员工除去gz,gw 为零的情况
                sizeBtyArchivesNew = this.baseMapper.updateAttendEmployeeMothOnlyInShopByDzAccountWithOutGzGw(attendAuditBtyArchivesListBtyArchives,param.getAttendMonth());
            }else{
                //更新到这个店，所有本店员工，未进行过调店到其他店的员工和调店到本店的员工信息！,除去店长那边的信息
                sizeBtyArchivesOld = this.baseMapper.updateAttendEmployeeMothOnlyInShopByDzAccount(AttendEmployeeMonthList,param.getAttendMonth());
            }
        }
        //插入相关数据这些新建的员工数据，根据店长电话，提交月份
        int sizeAddList = this.attendAuditBtyArchivesService.intoAttendEmployeeMonthListByDzPhone(param.getAccount(),param.getAttendMonth());

        //  若店长已经填写了考勤信息，则可以进行计算员工现有工资信息
        // 查询到本店的员工信息
        AttendAuditManagerSetParam managerSetParam = new AttendAuditManagerSetParam();
        managerSetParam.setAccount(param.getAccount());
        managerSetParam.setAttendMonth(param.getAttendMonth());
        List<AttendAuditManagerSetResult> list =  this.getEmployeeListMonthByManagerSetParam(managerSetParam);
        // 将本店员工的信息重新计算工资数据，
        //（判断考勤天数和公休天数是否为null或者0，判断考勤工资是否为null和0），如果其中一个值未空则，进行清空当条记录的应发工资数据
        List<AttendAuditManagerSetResult> listNew = batchUpdateShouldPay(list,managerSetParam.getAccount());
        //  更新本店员工的信息，
        //（判断考勤天数和公休天数是否为null或者0，判断考勤工资是否为null和0），如果其中一个值未空则，进行清空当条记录的应发工资数据
        int sizeUpdateList = this.baseMapper.batchUpdateShouldPayByAttendAuditManagerSetResult(listNew);
        return sizeBtyArchivesOld+sizeBtyArchivesNew+sizeAddList;
    }

    //setEmployeeListByDzPhoneRestartForContrast


    /**
     * 将本店所有员工员工的信息重新计算工资数据，
     * @param list
     * @return
     */
    private List<AttendAuditManagerSetResult> batchUpdateShouldPay(List<AttendAuditManagerSetResult> list,String account) {
        List<AttendAuditManagerSetResult> listNew = new ArrayList<AttendAuditManagerSetResult>();
        for(int i = 0;i<list.size();i++){
            AttendAuditManagerSetResult attendAuditManagerSetResult = list.get(i);

            AttendAuditManagerSetResult attendAuditManagerSetResultNew = this.calculateEmployeeSalary(attendAuditManagerSetResult,account);
            //（判断考勤天数和公休天数是否为null或者0，判断gz和gw工资是否共同为零），如果其中一个值未空则，进行清空当条记录的应发工资数据
            //职位为空
            //考勤天数为空

            //修改公休天数为空的问题
            if(ToolUtil.isEmpty(attendAuditManagerSetResultNew.getZw())
                    ||ToolUtil.isEmpty(attendAuditManagerSetResultNew.getAttendanceDays())){
                attendAuditManagerSetResultNew.setShouldPay(null);
            }
            //基本工资
            BigDecimal gz = attendAuditManagerSetResult.getGz();
            //岗位工资
            BigDecimal gw = attendAuditManagerSetResult.getGw();
            //gz和gw共同为空
            if(gz.equals(BigDecimal.ZERO)&& gw.equals(BigDecimal.ZERO)){
                attendAuditManagerSetResultNew.setShouldPay(null);
            }

            listNew.add(attendAuditManagerSetResultNew);
        }
        return listNew;
    }

    /**
     * 将这些员工中gw和gz中为零的情况不进行排除数据，则进行排除员工信息同步
     * @param attendEmployeeMonthList
     * @param attendAuditBtyArchivesListBtyArchives
     * @return
     */
    private List<AttendEmployeeMonth> dealWith(List<AttendEmployeeMonth> attendEmployeeMonthList, List<AttendAuditBtyArchives> attendAuditBtyArchivesListBtyArchives) {
        List<AttendEmployeeMonth> attendEmployeeMonthListNew = new ArrayList<AttendEmployeeMonth>();
        for(int i = 0 ; i<attendEmployeeMonthListNew.size() ; i++){
            AttendEmployeeMonth attendEmployeeMonth = attendEmployeeMonthListNew.get(i);
            boolean flag = false;
            for(int j = 0 ; j<attendAuditBtyArchivesListBtyArchives.size() ; j++){
                AttendAuditBtyArchives attendAuditBtyArchives = attendAuditBtyArchivesListBtyArchives.get(i);
                //判断这个员工是新员工
                if(attendEmployeeMonth.getBtyArchicesId().equals(attendAuditBtyArchives.getId())){
                    flag = true;
                }
            }
            //员工不是新员工的则进行添加到列表中
            if(!flag){
                attendEmployeeMonthListNew.add(attendEmployeeMonth);
            }
        }
        return attendEmployeeMonthListNew;
    }

    /**
     * （店长考勤修改页面+重建考勤信息） 同步考勤信息前的验证
     * @param attendAuditManagerSetParam
     * @return
     * update
     */
    @Override
    public List<Map<String,AttendAuditManagerSetResult>> contrastEmployeeListByDzPhoneRestart(AttendAuditManagerSetParam attendAuditManagerSetParam){
        List<Map<String,AttendAuditManagerSetResult>> list = new ArrayList<Map<String, AttendAuditManagerSetResult>>();

        // 获取同步的考勤信息
        // 获取店长本月的考勤信息
        List<AttendAuditManagerSetResult> attendAuditManagerSetResultList = getEmployeeListMonthByManagerSetParam(attendAuditManagerSetParam);
        //若获取的考勤信息为空，则返回空
        if(attendAuditManagerSetResultList.size() == 0){
            return list;
        }

        // 获取店长所要考勤的店的信息
        AttendAuditBtyArea attendAuditBtyArea = this.attendAuditBtyAreaService.getShopInfoByDzPhone(attendAuditManagerSetParam.getAccount());

        //获取人事中最新的数据,根据店名或者bh，
        List<AttendAuditBtyArchives> attendAuditBtyArchivesList = this.attendAuditBtyArchivesService.getBtyArchivesListByBhListOrDm(attendAuditManagerSetResultList,attendAuditBtyArea.getDm());
        // 进行对比

        // 将对比值，不相同的人拿出来，以考勤信息为主的
        //若他们的值等于零则没必要对比
        if(attendAuditManagerSetResultList.size()==0||attendAuditBtyArchivesList.size()==0){
            return list;
        }

        //以考勤信息为主，将信息进行对比，主要是获取到老员工，xm,zw,sfz,yhk,sjh,gz,gw 不想等的情况
        list = contrastAttendAuditAndAuditBtyArchivesOne(list,attendAuditManagerSetResultList,attendAuditBtyArchivesList);


        //以人事信息为主，将信息进行对比，主要是获取到老员工，中有，没有数据的员工信息，若被调走，不需要管，若是从其他店调过来的，则查询是否是跨营运经理了
        //若跨运营经理了，则查询将这个人在跨运营经理的原来的店，调到本店，
        list = contrastAttendAuditAndAuditBtyArchivesTwo(list,attendAuditManagerSetResultList,attendAuditBtyArchivesList,attendAuditBtyArea);

        //确认：删除的人员入离职人员信息表，若此人是老员工，且在人事档案中没有查询到，且在离职人员信息表中，则判断该员工是离职员工，将离职人员数据进行删除；

        //确认：人员若跨运营经理调店，则判断该员工是被人事档案中调走的人员，将调走的在本店删除

        return list;
    }



    /**
     * 以考勤信息为主，将信息进行对比，主要是获取到老员工，xm,zw,sfz,yhk,sjh,gz,gw 不想等的情况
     *
     * 主方法：contrastEmployeeListByDzPhoneRestart
     */

    private List<Map<String, AttendAuditManagerSetResult>> contrastAttendAuditAndAuditBtyArchivesOne(List<Map<String, AttendAuditManagerSetResult>> list, List<AttendAuditManagerSetResult> attendAuditManagerSetResultList, List<AttendAuditBtyArchives> attendAuditBtyArchivesList) {

        for(int i = 0 ;i<attendAuditManagerSetResultList.size();i++){
            //判断有编号相等的数据吗，若有则继续，若没有，则判断是不是已经离职，（非店长添加员工，非钉钉添加员工）

            boolean bhEqual = false;

            for(int j = 0 ;j<attendAuditBtyArchivesList.size();j++){
                //若编号相等，则证明是同一个员工
                if(attendAuditManagerSetResultList.get(i).getBh().equals(attendAuditBtyArchivesList.get(j).getBh())){

                    bhEqual = true;

                    //判断有没有被跨运营经理调店的，
                    //1档案数据，查询店名表中，数据,根据店名名字
                    AttendAuditBtyArea attendAuditBtyAreaDA =  this.attendAuditBtyAreaService.getShopInfoByDm(attendAuditBtyArchivesList.get(j).getDm());

                    //2考勤数据，查询店名表中，数据,根据店名名字
                    AttendAuditBtyArea attendAuditBtyAreaKQ =  this.attendAuditBtyAreaService.getShopInfoByDm(attendAuditManagerSetResultList.get(i).getDm());

                    //3对比运营经理，若相同，则不做处理，若不同，则判断，将考勤数据记录，待同步的时候删除
                    if(ToolUtil.isNotEmpty(attendAuditBtyAreaDA.getYyjl())&&ToolUtil.isNotEmpty(attendAuditBtyAreaKQ.getYyjl())){
                        //对比运营经理，相同的云应经理，则继续往后走，暂时不做任何处理
                        if(attendAuditBtyAreaDA.getYyjl().equals(attendAuditBtyAreaKQ.getYyjl())){
//                            Map<String,AttendAuditManagerSetResult> map = new HashMap<String,AttendAuditManagerSetResult>();
//                            AttendAuditManagerSetResult oldRecord = new AttendAuditManagerSetResult();
//                            ToolUtil.copyProperties(attendAuditBtyArchivesList.get(j),oldRecord);
//                            map.put("oldRecord",oldRecord);
//                            map.put("newRecord",attendAuditManagerSetResultList.get(i));
//                            list.add(map);
                        }else{
                            Map<String,AttendAuditManagerSetResult> map = new HashMap<String,AttendAuditManagerSetResult>();
                            map.put("newRecord",attendAuditManagerSetResultList.get(i));
                            list.add(map);
                        }
                    }


                    boolean flag = true;
                    //若不是新员工，则对比，xm,zw,sfz,yhk,手机号，gz,gw
                    String synchronousStatus = String.valueOf(attendAuditManagerSetResultList.get(i).getSynchronousStatus());
                    String btyArchicesNewEmp = "";
                    if(ToolUtil.isNotEmpty(attendAuditManagerSetResultList.get(i).getBtyArchicesNewEmp())){
                        btyArchicesNewEmp= String.valueOf(attendAuditManagerSetResultList.get(i).getBtyArchicesNewEmp());
                    }else{
                        btyArchicesNewEmp = "0";
                    }


                    if(synchronousStatus.equals("0")&&btyArchicesNewEmp.equals("0")){
                        //若有职位变动，则不判断，任何职位和薪资的变动了，并且职位，是正式改非正式，或者非正式改正式，则不进行判断
                        //获取旧的员工信息，若旧的员工职位和新的员工职位相等，工资不允许修改，赋值原来的数值！
                        String positionFormal =  "迎宾,前厅员工,后厨员工,员工,储备";
                        String positionNotFormal = "钟点工,兼职,小时工";

                        //人事档案中,职位不为空 并且一下两种情况符合一种的，不用同步
                        //1.考勤中为非正式岗位，人事档案中为非正式岗位
                        //2.考勤中为正式员工，人事档案中为正式员工的
                        if(ToolUtil.isNotEmpty(attendAuditManagerSetResultList.get(i).getZwOld())&&
                                ((positionNotFormal.indexOf(attendAuditManagerSetResultList.get(i).getZw())>-1&&positionFormal.indexOf(attendAuditBtyArchivesList.get(j).getZw())>-1)||(positionFormal.indexOf(attendAuditManagerSetResultList.get(i).getZw())>-1&&positionNotFormal.indexOf(attendAuditBtyArchivesList.get(j).getZw())>-1))){

                        }else{
                            //...
                            String positionall =  "迎宾,前厅员工,后厨员工,员工,储备,钟点工,兼职,小时工";

                            //若不是在设的职位以内，则需要对比职位，然后同步职位信息
                            if(positionall.indexOf(attendAuditBtyArchivesList.get(j).getZw())<0){
                                //职位不相等
                                if(!attendAuditManagerSetResultList.get(i).getZw().equals(attendAuditBtyArchivesList.get(j).getZw())){
                                    flag = false;
                                }
                            }else{
                                attendAuditBtyArchivesList.get(j).setZw("notSync"+attendAuditBtyArchivesList.get(j).getZw());
                            }
                            //若职位都是兼职，并且一个是钟点工，一个是兼职
                            boolean changeGz = true;
                            if(positionNotFormal.indexOf(attendAuditManagerSetResultList.get(i).getZw())>-1&&positionNotFormal.indexOf(attendAuditBtyArchivesList.get(j).getZw().replace("notSync",""))>-1){
                                if(!attendAuditManagerSetResultList.get(i).getZw().equals(attendAuditBtyArchivesList.get(j).getZw().replace("notSync",""))){
                                    changeGz =false;
                                }
                            }
                            if(changeGz){
                                //工资不相等
                                if(!attendAuditManagerSetResultList.get(i).getGz().equals(attendAuditBtyArchivesList.get(j).getGz())){
                                    flag = false;
                                }
                                //岗位工资不相等
                                if(!attendAuditManagerSetResultList.get(i).getGw().equals(attendAuditBtyArchivesList.get(j).getGw())){
                                    flag = false;
                                }
                            }

                            //姓名不相等
                            if(!attendAuditManagerSetResultList.get(i).getXm().equals(attendAuditBtyArchivesList.get(j).getXm())){
                                flag = false;
                            }
                            //身份证不相等
                            if(!attendAuditManagerSetResultList.get(i).getSfz().equals(attendAuditBtyArchivesList.get(j).getSfz())){
                                flag = false;
                            }
                            //银行卡不相等
                            if(!attendAuditManagerSetResultList.get(i).getYhk().equals(attendAuditBtyArchivesList.get(j).getYhk())){
                                if(attendAuditBtyArchivesList.get(j).getYhkStatus().equals("1")&&attendAuditManagerSetResultList.get(i).getYhkStatus().equals("2")){
                                    flag = false;
                                }else{
                                    attendAuditBtyArchivesList.get(j).setYhk("notSync"+attendAuditBtyArchivesList.get(j).getYhk());
                                }
                            }
                            //手机号不相等
                            if(!attendAuditManagerSetResultList.get(i).getTel().equals(attendAuditBtyArchivesList.get(j).getTel())){
                                flag = false;
                            }
                        }

                    }
                    //若是新员工，则对比xm,sjh,sfz,yhk，手机号,不对比zw,gz,gw工资
                    //姓名不相等

                    //若其中有不相等的，则需要返回
                    if(flag == false){
                        Map<String,AttendAuditManagerSetResult> map = new HashMap<String,AttendAuditManagerSetResult>();
                        AttendAuditManagerSetResult oldRecord = new AttendAuditManagerSetResult();
                        ToolUtil.copyProperties(attendAuditBtyArchivesList.get(j),oldRecord);
                        map.put("oldRecord",oldRecord);
                        map.put("newRecord",attendAuditManagerSetResultList.get(i));
                        list.add(map);
                    }
                    //查到相同的数据了，则不用再循环内部，跳出循环，进行下一次的查询
                    break;
                }
            }
            if(!bhEqual){
                AttendAuditManagerSetResult attendAuditManagerSetResult = attendAuditManagerSetResultList.get(i);
                // 判断有编号相等的数据吗，若有则继续，若没有，则判断是不是已经离职，（非店长添加员工，非钉钉添加员工）
                if(!"0".equals(String.valueOf(attendAuditManagerSetResult.getSynchronousStatus()))||(ToolUtil.isNotEmpty(attendAuditManagerSetResult.getDingdingNewEmp())&&attendAuditManagerSetResult.getDingdingNewEmp().equals("T"))){

                }else{
                    //编号不为空，则进行查询离职人员信息表，若存在，则这个人为离职人员，则进行删除
                    if(ToolUtil.isNotEmpty(attendAuditManagerSetResult.getBh())){
                        //根据编号查询离职人员信息表
                        List<AttendAuditBtyArchives>  archivesList = this.attendAuditBtyArchivesService.getArchivesListByBh(attendAuditManagerSetResult);
                        //若此人是离职人员，则将此人删除；
                        if(archivesList.size()>0){
                            Map<String,AttendAuditManagerSetResult> map = new HashMap<String,AttendAuditManagerSetResult>();
                            map.put("newRecord",attendAuditManagerSetResult);
                            list.add(map);
                        }
                    }
                }
            }
        }

        return list;
    }

    /**
     * 根据 ArchicesId 和 考勤月份，查询此员工，是否在本月做过考考勤
     * 若做过，则返回 AttendEmployeeMonth
     * 若没有，若没有做过则返回 new AttendEmployeeMonth(),空的数据类
     * @param attendEmployeeMonth
     * @return
     *
     * 主方法：contrastEmployeeListByDzPhoneRestart
     */
    private AttendEmployeeMonth getAttendEmployeeMonthByBtyArchicesIdAndAttendMonth(AttendEmployeeMonth attendEmployeeMonth){
        AttendEmployeeMonth attendEmployeeMonthOld = new AttendEmployeeMonth();
        LambdaQueryWrapper<AttendEmployeeMonth> queryWrapper = new LambdaQueryWrapper<AttendEmployeeMonth>();
        queryWrapper.eq(AttendEmployeeMonth::getBtyArchicesId,attendEmployeeMonth.getBtyArchicesId());
        queryWrapper.eq(AttendEmployeeMonth::getAttendMonth,attendEmployeeMonth.getAttendMonth());

        List<AttendEmployeeMonth> list = this.baseMapper.selectList(queryWrapper);
        if(list.size()>0){
            attendEmployeeMonthOld = list.get(0);
        }
        return  attendEmployeeMonthOld;
    }

    /**
     * 以人事信息为主，将信息进行对比，主要是获取到老员工，中有，没有数据的员工信息，若被调走，不需要管，若是从其他店调过来的，则查询是否是跨营运经理了
     * 若跨运营经理了，则查询将这个人在跨运营经理的原来的店，调到本店，
     *
     * 主方法：contrastEmployeeListByDzPhoneRestart
     */
    private List<Map<String, AttendAuditManagerSetResult>> contrastAttendAuditAndAuditBtyArchivesTwo(List<Map<String, AttendAuditManagerSetResult>> list, List<AttendAuditManagerSetResult> attendAuditManagerSetResultList, List<AttendAuditBtyArchives> attendAuditBtyArchivesList,AttendAuditBtyArea attendAuditBtyArea) {

        //获取本月考勤的日期；
        Map<String,String> attendMonthMap = attendAuditBtyArchivesService.intoAttendEmployeeMonthListValidationParam(null,null);
        String attendMonth = attendMonthMap.get("attendMonth").replaceAll("-","");

        // 将人事新加的员工取出来，已人事信息为主的，除去被同营运经理下调离本店的员工的编号bh；
        // 若员工，在考勤中，在另一个营运经理下属，则将，另一个运营经理下的员工数据进行删除；

        for(int i = 0 ;i<attendAuditBtyArchivesList.size();i++){
            AttendAuditBtyArchives attendAuditBtyArchives = attendAuditBtyArchivesList.get(i);
            boolean flag = false;
            for(int j = 0 ;j<attendAuditManagerSetResultList.size();j++){
                //若人事添加的员工已经在考勤里面，则不需要做任何的处理；
                if(attendAuditManagerSetResultList.get(j).getBh().equals(attendAuditBtyArchives.getBh())){
                    flag = true;
                    break;
                }
            }



            //若人事数据没有在本店的考勤中，则需要处理， 验证这个员工有没有调店，若被(同运营经理下的店)调店调走了，也不需要管
            //若被不是同运营经理下的员工调店了，则删除原先店的考勤信息，将信息同步到本店中

            if(flag == false){
                // 根据编号和考勤月份，查询到那些员工已经做了考勤了，但是不在本店做的考勤，
                //根据编号信息查询相应的信息
                AttendEmployeeMonth attendEmployeeMonthOld = new AttendEmployeeMonth();
                attendEmployeeMonthOld.setBh(attendAuditBtyArchives.getBh());

                //查询所有此编号的员工本月做过的考勤，
                AttendEmployeeMonth attendEmployeeMonth = getAttendEmployeeMonthByBh(attendEmployeeMonthOld,attendMonth);

                //查询同店长一个运营经理下的此编号的员工本月做过的考勤，
                AttendEmployeeMonth attendEmployeeMonthOneYyjl = getAttendEmployeeMonthByBhOneYyjl(attendEmployeeMonthOld,attendMonth,attendAuditBtyArea);

//                //若有数据，并且店名和店长所在店不一致，则进行判断，是已经做过考勤的员工信息
//                if(ToolUtil.isNotEmpty(attendEmployeeMonth.getDm())){
//                    if(attendEmployeeMonth.getDm().equals(attendAuditBtyArchives.getDm())){
//
//                    }else{
//                        flag = true;
//                    }
//                }
                //若相同的运营经理下有数据
                if(ToolUtil.isNotEmpty(attendEmployeeMonthOneYyjl.getId())){
                    if(ToolUtil.isNotEmpty(attendEmployeeMonthOneYyjl.getDm())){
                        if(attendEmployeeMonthOneYyjl.getDm().equals(attendAuditBtyArchives.getDm())){

                        }else{
                            flag = true;
                        }
                    }
                }else if(ToolUtil.isNotEmpty(attendEmployeeMonth.getId())){
                    //若不同的运营经理下有该员工数据，则证明该是从不同的运营经理调店过来的，需要添加店
                    flag = true;

                    //若不同的运营经理，则判断，这个人是否在本次做过考勤，若没有，则直接添加
                    //若已经做过考勤，没有提交的情况下，或者提交了提交了，应发工资为不发的情况

                    AttendEmployeeMonth attendEmployeeMonthParam = new AttendEmployeeMonth();
                    attendEmployeeMonthParam.setBtyArchicesId(attendEmployeeMonth.getBtyArchicesId());
                    Map<String,String> mapAttendMonth = this.attendAuditService.getAttendMonth();
                    String attendMonthStr = mapAttendMonth.get("attendMonth").replaceAll("-","");
                    attendEmployeeMonthParam.setAttendMonth(attendMonthStr);

                    //获取到旧的数据
                    AttendEmployeeMonth attendEmployeeMonthOldRecord = getAttendEmployeeMonthByBtyArchicesIdAndAttendMonth(attendEmployeeMonthParam);

                    //是否，有本月考勤，之后还要跨运营经理同步；
                    Boolean flagHaveAttendEmployeeMonth = false;

                    if(ToolUtil.isNotEmpty(attendEmployeeMonthOldRecord.getId())){
                        //若不发工资则直接调走
                        if(attendEmployeeMonthOldRecord.getPayWage().equals("1")){
                            flagHaveAttendEmployeeMonth = true;
                        }else{
                            //查询此员工原有的考勤记录状态；
                            AttendAudit attendAuditOld = attendAuditService.getById(attendEmployeeMonthOldRecord.getAttendAuditId());
                            if(attendAuditOld.getAuditStatus().equals(AttendAuditStatusEnum.SUBMIT_AUDIT.getCode()) || attendAuditOld.getAuditStatus().equals(AttendAuditStatusEnum.SUBMIT_THROUGH.getCode())){
                                 //员工已经在其他店进行了考勤，并且已经提交或者被审核通过无法同步
                            }else{
                                flagHaveAttendEmployeeMonth = true;
                            }
                        }

                    }else{
                        flagHaveAttendEmployeeMonth = true;
                    }

                    if(flagHaveAttendEmployeeMonth){
                        Map<String,AttendAuditManagerSetResult> map = new HashMap<String,AttendAuditManagerSetResult>();
                        AttendAuditManagerSetResult oldRecord = new AttendAuditManagerSetResult();
                        ToolUtil.copyProperties(attendAuditBtyArchivesList.get(i),oldRecord);
                        map.put("oldRecord",oldRecord);
                        list.add(map);
                    }
                }
            }
            //若没有查询到，则是新员工，若查询到了，则需要进行同步，
            if(flag == false){
                Map<String,AttendAuditManagerSetResult> map = new HashMap<String,AttendAuditManagerSetResult>();
                AttendAuditManagerSetResult oldRecord = new AttendAuditManagerSetResult();
                ToolUtil.copyProperties(attendAuditBtyArchivesList.get(i),oldRecord);
                map.put("oldRecord",oldRecord);
                list.add(map);
            }
        }

        return list;
    }



    /**
     * 重写的同步方法
     * @param attendAuditDdSupervisorParam
     * @return
     */
    @Override
    public int setEmployeeListByDzPhoneRestartForContrast(AttendAuditDdSupervisorParam attendAuditDdSupervisorParam) {
        AttendAuditManagerSetParam attendAuditManagerSetParam = new AttendAuditManagerSetParam();
        ToolUtil.copyProperties(attendAuditDdSupervisorParam,attendAuditManagerSetParam);
        List<Map<String,AttendAuditManagerSetResult>> list = contrastEmployeeListByDzPhoneRestart(attendAuditManagerSetParam);



        //需要同步的数据大于零的数据
        if(list.size()>0){
            for(int i = 0 ;i < list.size();i++){
                Map<String,AttendAuditManagerSetResult> map = list.get(i);
                AttendAuditManagerSetResult oldRecord = map.get("oldRecord");
                AttendAuditManagerSetResult newRecord = map.get("newRecord");

                //若人事表中有，考勤信息表中有，则更新
                if(ToolUtil.isNotEmpty(oldRecord)&&ToolUtil.isNotEmpty(newRecord)){

                    //将档案中的，xm,zw,sfz,yhk,gz,gw,手机号，根据id同步到信息的
                    int updateSize = notEmptyOldRecordAndNotEmptyNewRecord(oldRecord,newRecord);
                }

                //若人事表有，考勤信息表中没有，则添加相应信息，进行插入
                // 判断是否已经做过考勤，并且，将是否发工资，字段修改为不发工资提交的，或者未提交的，则进行调店的处理
                if(ToolUtil.isNotEmpty(oldRecord)&&ToolUtil.isEmpty(newRecord)){

                    int updateSize = notEmptyOldRecordAndEmptyNewRecord(oldRecord,newRecord,attendAuditManagerSetParam);
                }

                // 若考勤信息表中有，人事表没有，则删除考勤中的相应的信息，
                if(ToolUtil.isEmpty(oldRecord)&&ToolUtil.isNotEmpty(newRecord)){
                    //若考勤信息表中有，人事表没有，则删除考勤中的相应的信息，
                    int updateSize = emptyOldRecordAndNotEmptyNewRecord(oldRecord,newRecord,attendAuditManagerSetParam);
                }
            }
            //获取本月考勤的日期；
            Map<String,String> attendMonthMap = attendAuditBtyArchivesService.intoAttendEmployeeMonthListValidationParam(null,null);
            String attendMonth = attendMonthMap.get("attendMonth").replaceAll("-","");




            // 计算员工薪资，重新计算；
            //  若店长已经填写了考勤信息，则可以进行计算员工现有工资信息
            // 查询到本店的员工信息
            AttendAuditManagerSetParam managerSetParam = new AttendAuditManagerSetParam();
            managerSetParam.setAccount(attendAuditDdSupervisorParam.getAccount());
            managerSetParam.setAttendMonth(attendMonth);
            List<AttendAuditManagerSetResult> listShouldPay =  this.getEmployeeListMonthByManagerSetParam(managerSetParam);
            // 将本店员工的信息重新计算工资数据，
            //（判断考勤天数和公休天数是否为null或者0，判断考勤工资是否为null和0），如果其中一个值未空则，进行清空当条记录的应发工资数据
            List<AttendAuditManagerSetResult> listNew = batchUpdateShouldPay(listShouldPay,managerSetParam.getAccount());
            //  更新本店员工的信息，
            //（判断考勤天数和公休天数是否为null或者0，判断考勤工资是否为null和0），如果其中一个值未空则，进行清空当条记录的应发工资数据
            int sizeUpdateList = this.baseMapper.batchUpdateShouldPayByAttendAuditManagerSetResult(listNew);

        }else{
            return list.size();
        }

        return list.size();

    }




    /**
     * 将档案中的，xm,zw,sfz,yhk,gz,gw,手机号，根据id同步到信息的
     * @author wjk
     * @Date 2021-12-22
     * @param oldRecord
     * @param newRecord
     * @return
     *
     * 主方法 setEmployeeListByDzPhoneRestartForContrast
     *
     */
    private int notEmptyOldRecordAndNotEmptyNewRecord(AttendAuditManagerSetResult oldRecord, AttendAuditManagerSetResult newRecord) {

        //ToolUtil.copyProperties(oldRecord,newRecord);
        newRecord.setXm(oldRecord.getXm());
        newRecord.setSfz(oldRecord.getSfz());
        //新增手机号的对比
        newRecord.setTel(oldRecord.getTel());

        boolean changeGz = true;
        if(oldRecord.getZw().indexOf("notSync")>-1){
            newRecord.setZw(newRecord.getZw());
            String positionNotFormal = "钟点工,兼职,小时工";
            if(positionNotFormal.indexOf(newRecord.getZw())>-1&&positionNotFormal.indexOf(oldRecord.getZw().replace("notSync",""))>-1){
                if(!newRecord.getZw().equals(oldRecord.getZw().replace("notSync",""))){
                    changeGz =false;
                }
            }
        }else{
            newRecord.setZw(oldRecord.getZw());
        }

        if(oldRecord.getYhk().indexOf("notSync")>-1){
            newRecord.setYhk(newRecord.getYhk());
        }else{
            newRecord.setYhk(oldRecord.getYhk());
        }
        //只有在兼职，钟点工互相改的情况下，工资不能修改为人事工资
        if(changeGz){
            newRecord.setGz(oldRecord.getGz());
            newRecord.setGw(oldRecord.getGw());
        }
        //更新，xm,zw,sfz,yhk,gz,gw,根据编号，
        return this.baseMapper.updateAttendEmployeeMonthNewRecord(newRecord);
    }


    /**
     * 若人事表有，考勤信息表中没有，则添加相应信息，进行插入
     * 判断是否已经做过考勤，并且，将是否发工资，字段修改为不发工资提交的，或者未提交的，则进行调店的处理
     * @author wjk
     * @Date 2021-12-22
     * @param oldRecord
     * @param newRecord
     * @param attendAuditManagerSetParam
     * @return
     *
     * 主方法 setEmployeeListByDzPhoneRestartForContrast
     *
     */
    private int notEmptyOldRecordAndEmptyNewRecord(AttendAuditManagerSetResult oldRecord, AttendAuditManagerSetResult newRecord,AttendAuditManagerSetParam attendAuditManagerSetParam) {
        //获取本月考勤的日期；
        Map<String,String> attendMonthMap = attendAuditBtyArchivesService.intoAttendEmployeeMonthListValidationParam(null,null);
        String attendMonth = attendMonthMap.get("attendMonth").replaceAll("-","");

        //根据店长电话获取店长的信息；
        AttendAuditBtyArchives attendAuditBtyArchivesDz = attendAuditBtyArchivesService.getOneByPhone(attendAuditManagerSetParam.getAccount());

        //查询是否有提交的
        AttendEmployeeMonth attendEmployeeMonthOld = this.getById(Long.valueOf(attendMonth+oldRecord.getId().toString()));

        //查询这个店这个月的考勤信息
        AttendAudit attendAuditOld = this.attendAuditService.getById(Long.valueOf(attendMonth+attendAuditBtyArchivesDz.getId()));

        int updateOrAddSize = 0;
        //若有本月的考勤信息，则尽心调店处理
        if(ToolUtil.isNotEmpty(attendEmployeeMonthOld)){
            attendEmployeeMonthOld.setDmOld(attendEmployeeMonthOld.getDm());
            attendEmployeeMonthOld.setDm(attendAuditBtyArchivesDz.getDm());

            //记录该员工的当月的考勤记录信息；
            attendEmployeeMonthOld.setAttendAuditId(attendAuditOld.getId());

            //将调店员工的区域，和店长的区域对应
            attendEmployeeMonthOld.setQy(attendAuditBtyArchivesDz.getQy());
            attendEmployeeMonthOld.setEqy(attendAuditBtyArchivesDz.getEqy());

            updateOrAddSize = this.baseMapper.updateById(attendEmployeeMonthOld);

        }else{
            //此处插入相关信息,店长手机号，查询店长考勤信息，
            // attendAuditManagerSetParam.getAccount();
            System.out.println("此处进行插入！！！");
            //考勤的月份
            oldRecord.setAttendMonth(attendMonth);
            //同步的月份
            oldRecord.setSynchronousMonth(sdf.format(new Date()));
            //是否发工资为发
            oldRecord.setPayWage(oldRecord.getZt());
            //在职状态为在职
            oldRecord.setZtNew(0);

            //查询这个员工，应该在那个店进行考勤的信息；
            oldRecord.setAttendAuditId(attendAuditOld.getId());
            //同步状态
            oldRecord.setSynchronousStatus(0);
            //增加AttendAuditId
            oldRecord.setBtyArchicesId(oldRecord.getId());
            //增加Id
            oldRecord.setId(Long.valueOf(attendMonth+oldRecord.getBtyArchicesId().toString()));
            AttendEmployeeMonth attendEmployeeMonth = new AttendEmployeeMonth();
            ToolUtil.copyProperties(oldRecord,attendEmployeeMonth);

            //基本工资
            BigDecimal gz = attendEmployeeMonth.getGz();
            //岗位工资
            BigDecimal gw = attendEmployeeMonth.getGw();
            //gz和gw共同为空
            if(gz.equals(BigDecimal.ZERO)&& gw.equals(BigDecimal.ZERO)){
                attendEmployeeMonth.setBtyArchicesNewEmp("1");
            }else{
                attendEmployeeMonth.setBtyArchicesNewEmp("0");
            }

            boolean falg = this.save(attendEmployeeMonth);
            if(falg){
                updateOrAddSize = 1;
            }
        }

        return updateOrAddSize;
    }

    /**
     * 若考勤信息表中有，人事表没有，则删除考勤中的相应的信息
     * @param oldRecord
     * @param newRecord
     * @param attendAuditManagerSetParam
     * @return
     */
    private int emptyOldRecordAndNotEmptyNewRecord(AttendAuditManagerSetResult oldRecord, AttendAuditManagerSetResult newRecord, AttendAuditManagerSetParam attendAuditManagerSetParam) {

        System.out.println("此处进行删除数据！！！");
        //获取本月考勤的日期；
        Map<String,String> attendMonthMap = attendAuditBtyArchivesService.intoAttendEmployeeMonthListValidationParam(null,null);
        String attendMonth = attendMonthMap.get("attendMonth").replaceAll("-","");
        return this.baseMapper.deleteById(newRecord.getId());

    }


    /**
     * 同步回人资档案表的数据，从这里
     * 每一个月三号凌晨，定时同步，需要做成定时任务
     * @param param
     * @return
     * @Deprecated 检查只能同步一次，
     *
     */
    @Override
    public Map<String,String> synchronousAttendEmployeeMonthToBtyArchives(AttendAuditDdSupervisorParam param) {
        Map<String,String> map = new HashMap<String,String>();
        if(ToolUtil.isEmpty(param)||ToolUtil.isEmpty(param.getAttendMonth())){
            map.put("flag","false");
            map.put("message","原因：未提供有效的参数AttendMonth，参数为考勤月份,参数格式YYYYMM,参数实例：202110，同步10月份考勤数据");
            return map;
        }
        //默认创建考勤的日期是上个月
//        Date date = new Date();
//        String attendMonth = sdf.format(calculateMonth(date,-1));
//        SimpleDateFormat daySdf = new SimpleDateFormat("dd");
//        String day = daySdf.format(date);
//        if(param.getAttendMonth().equals(attendMonth)&&day.equals("03")){
            //备份这这份表
            String tableName = "bty_archives_bak"+sdfs.format(new Date());
            int sizeBak = this.baseMapper.bakbtyArchives(tableName);
            // 查找出已经审核通过的数据，统计数量
            List<AttendEmployeeMonth> attendEmployeeMonthList = this.baseMapper.auditStatusForSuccessEmployee(param);
            // 查找出已经审核通过的店,统计数量
            List<AttendAuditBtyArea> AttendAuditBtyAreaList = this.baseMapper.auditStatusForSuccessShopName(param);

            // 同步的店
            int size = this.baseMapper.auditStatusForSuccess(param);
            //更新所有新的员工的状态，信息
            int sizeforEmpNew =this.baseMapper.auditStatusForSuccessNewEmp(param);
            map.put("bakTableName",tableName);
            map.put("employee",String.valueOf(attendEmployeeMonthList.size()));
            map.put("shopSize",String.valueOf(AttendAuditBtyAreaList.size()));
            map.put("size",String.valueOf(size));
            map.put("sizeforEmpNew",String.valueOf(sizeforEmpNew));
            map.put("flag","true");
            map.put("message","同步成功。");
            return map;
//        }else{
//            map.put("未进行同步","同步时间必须是本月同步上个月考勤信息，在每月的03号");
//            return map;
//        }

    }

    /**
     * 同步回人资档案表的数据，从这里,同步单店的数据
     * @param param
     * @return
     * @Deprecated 根据店长的手机号，和单店的信息，
     */
    @Override
    public Map<String,String> synchronousAttendEmployeeMonthToBtyArchivesForOneShop(AttendAuditDdSupervisorParam param){
        Map<String,String> map = new HashMap<String,String>();
        if(ToolUtil.isEmpty(param)||ToolUtil.isEmpty(param.getAttendMonth())){
            map.put("未进行同步","原因：未提供有效的参数AttendMonth，参数为考勤月份,参数格式YYYYMM,参数实例：202110，同步10月份考勤数据");
            return map;
        }

        return map;

    }

    /**
     * 根据店长手机号，判断店长手下的员工的银行卡号是否正确，并验证银行卡是否重复
     * @author wjk
     * @Date 2021-12-17
     */
    @Override
    public Map<String, String> getYhkStatus(AttendEmployeeMonthParam attendEmployeeMonthParam, String account) {

        Map<String, String> map = new HashMap<String, String>();

        // 查询银行卡状态，若银行卡状态不正确，则直接返回
        Map<String, String> mapYhkInfo = getYhkInfo(attendEmployeeMonthParam.getYhk());

        map.put("cardName",mapYhkInfo.get("cardName"));
        map.put("bank",mapYhkInfo.get("bank"));
        map.put("yhkStatus",mapYhkInfo.get("yhkStatus"));
        if("2".equals(mapYhkInfo.get("yhkStatus"))){
            map.put("msg","银行卡号不正确，或者该银行卡处于异常状态，请重新输入银行卡号。");
            map.put("flag","false");
            return map;
        }
        //非必要   查询人员是否在人事档案表中，若有取出银行卡，和银行卡状态
//        if(ToolUtil.isNotEmpty(attendEmployeeMonthParam.getBtyArchicesId())){
//            AttendAuditBtyArchivesParam attendAuditBtyArchivesParam = new AttendAuditBtyArchivesParam();
//            attendAuditBtyArchivesParam.setId(Integer.valueOf(String.valueOf(attendEmployeeMonthParam.getBtyArchicesId())));
//            AttendAuditBtyArchives attendAuditBtyArchives = attendAuditBtyArchivesService.detailById(attendAuditBtyArchivesParam);
//            if(ToolUtil.isNotEmpty(attendAuditBtyArchives)){
//                System.out.println(attendAuditBtyArchives.getYhk());
//            }
//        }
        //查询银行卡在人事档案表是否有重复数据，若有重复数据， 取出重复数据的人员信息(非此员工)，
        List<AttendAuditBtyArchives> attendAuditBtyArchivesList = attendAuditBtyArchivesService.getListByYhk(attendEmployeeMonthParam);
        if(attendAuditBtyArchivesList.size()>0){
            //map.put("msg","银行卡号和已入职的人员银行卡号重复，请核对银行卡是否属于本员工。银行卡号重复的人员("+attendAuditBtyArchivesList.get(0).getDm()+":"+attendAuditBtyArchivesList.get(0).getXm()+")");
            map.put("msg","银行卡号与人事档案中["+attendAuditBtyArchivesList.get(0).getDm()+"]"+attendAuditBtyArchivesList.get(0).getXm()+"的银行卡重复，请重新输入卡号");
            map.put("flag","false");
            return map;
            //System.out.println(attendAuditBtyArchivesList.get(0).getYhk());
        }

        //获取本月考勤的日期；
        Map<String,String> attendMonthMap = attendAuditBtyArchivesService.intoAttendEmployeeMonthListValidationParam(null,null);
        String attendMonth = attendMonthMap.get("attendMonth").replaceAll("-","");
        //查询银行卡在本月考勤，是否有重复数据，若有重复数据， 取出重复数据的人员信息(非此员工)，
        List<AttendEmployeeMonth> attendEmployeeMonthList = this.baseMapper.getListByYhk(attendEmployeeMonthParam,attendMonth);
        if(attendEmployeeMonthList.size()>0){
            AttendEmployeeMonth attendEmployeeMonth = attendEmployeeMonthList.get(0);
            String dm = attendEmployeeMonth.getDm();
            String xm = attendEmployeeMonth.getXm();

            //map.put("msg","银行卡号和本月考勤的人员银行卡号重复，请核对银行卡是否属于本员工。银行卡号重复的人员("+dm+":"+xm+")");
            map.put("msg","银行卡号与本月考勤中["+dm+"]"+xm+"的银行卡重复，请重新输入卡号");

            map.put("flag","false");
            return map;
            //System.out.println(attendAuditBtyArchivesList.get(0).getYhk());
        }
        map.put("flag","true");
        return map;
    }

    /**
     * 同步单人的姓名
     *
     * @author wjk
     * @Date 2021-03-09
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String,String> synchronousNameById(Long id) {

        Map<String,String> map = new HashMap<String,String>();

        AttendEmployeeMonth attendEmployeeMonthOld = this.getById(id);

        //判断员工在考勤档案中有没有
        if(ToolUtil.isEmpty(attendEmployeeMonthOld)||ToolUtil.isEmpty(attendEmployeeMonthOld.getId())){
            map.put("falg","false");
            map.put("message","未查询人员，请确认人员是否正确。");
            return map;
        }

        //判断员工在考勤档案中有没有
        if(ToolUtil.isEmpty(attendEmployeeMonthOld.getBtyArchicesId())){
            map.put("falg","false");
            map.put("message","未查询到人事档案信息，此人为新员工，或钉钉同步员工，无需同步姓名，店长可以直接修改员工姓名。");
            return map;
        }


        AttendAuditBtyArchives attendAuditBtyArchives = this.attendAuditBtyArchivesService.getById(attendEmployeeMonthOld.getBtyArchicesId());

        //判断员工在人事档案中有没有
        if(ToolUtil.isEmpty(attendAuditBtyArchives)||ToolUtil.isEmpty(attendAuditBtyArchives.getId())){
            map.put("falg","false");
            map.put("message","未查询到人事档案信息，此人为新员工，或钉钉同步员工，无需同步姓名，店长可以直接修改员工姓名。");
            return map;
        }

        //判断员工姓名和档案中是否一致
        if(attendEmployeeMonthOld.getXm().equals(attendAuditBtyArchives.getXm())){
            map.put("falg","false");
            map.put("message","员工姓名和档案中员工中姓名一致，无需同步员工姓名。");
            return map;
        }
        AttendEmployeeMonth AttendEmployeeMonthParam = new AttendEmployeeMonth();
        AttendEmployeeMonthParam.setId(attendEmployeeMonthOld.getId());
        AttendEmployeeMonthParam.setXm(attendAuditBtyArchives.getXm());

        //员工姓名不一致，则只根据员工的id 修改员工的姓名，与档案数据一致
        boolean updateFalg = this.baseMapper.updateAttendEmployeeMonthNameById(AttendEmployeeMonthParam);

        if(updateFalg){
            map.put("falg","true");
            map.put("message","同步成功。");
            return map;
        }
        map.put("falg","false");
        map.put("message","同步失败。");
        return map;
    }


    /**
     *  通过银行卡号获取银行简称
     * @param yhk
     * @return
     */
    public Map<String,String> getYhkInfo(String yhk){

        Map<String,String> map = new HashMap<String,String>();

        //银行名称
        String cardName = "";
        //银行简称
        String bank="";
        //银行卡，行号
        String hh="";

        String yhkStatus="2";

        String flag = "false";

        RestTemplate restTemplate = new RestTemplate();
        String url = "https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo="+yhk+"&cardBinCheck=true";
        String content = restTemplate.getForObject(url, String.class);
        JSONObject jsonObject = JSONObject.parseObject(content);

        if(ToolUtil.isNotEmpty(jsonObject.get("bank"))){
            bank = jsonObject.get("bank").toString();
            //银行名称
            cardName = btyArchivesService.cardUtil().get(bank);
            yhkStatus = "1";
            //通过银行简称获取行号
            hh= btyBxdaService.getBankCode(bank);
            flag = "true";

        } else {
            yhkStatus = "2";
            flag = "false";

        }
        map.put("yhk",yhk);
        map.put("cardName",cardName);
        map.put("bank",bank);
        map.put("hh",hh);
        map.put("yhkStatus",yhkStatus);
        map.put("flag",flag);
        return map;
    }














//    /**
//     * 同步回人资档案表的数据，从这里
//     * @param param
//     * @return
//     * @Deprecated 检查只能同步一次，
//     */
//    public Map<String,String> synchronousAttendEmployeeMonthToBtyArchivesFun(AttendAuditDdSupervisorParam param){
//        Map<String,String> map = new HashMap<String,String>();
//        //备份这这份表
//        String tableName = "bty_archives_"+sdfs.format(new Date());
//        int sizeBak = this.baseMapper.bakbtyArchives(tableName);
//        // 查找出已经审核通过的数据，统计数量
//        List<AttendEmployeeMonth> attendEmployeeMonthList = this.baseMapper.auditStatusForSuccessEmployee(param);
//        //查找出已经审核通过的店,统计数量
//        List<AttendAuditBtyArea> AttendAuditBtyAreaList = this.baseMapper.auditStatusForSuccessShopName(param);
//
//
//        //查找人员调店的员工，同步回去，dm , dm_old
//        int size4 = this.baseMapper.auditStatusForSuccessDm(param);
//
//        //查找人员人资新加的新员工，同步回去，gz,gw
//        int size5 = this.baseMapper.auditStatusForSuccessGzGw(param);
//
//        //查找所有个人添加的新员工，同步回去，新增人员编号，和所有人员信息，gz,gw 等
//        int size6 = this.baseMapper.auditStatusForSuccessAllNew(param);
//
//        //修改店长新加员工个人的状态数据
//        int size7 = this.baseMapper.auditStatusForSuccessAllNewSynchronous(param);
//
//
//        return map;
//    }


}
